<?php
/**
 * Protected functions for SLS_Bo Controller
 *
 */
class SLS_BoControllerProtected extends SiteProtected 
{
	public function init()
    {
        parent::init();        
    }
	
	/**
	 * Generate the main Menu
	 *
	 * @param XmlToolBox $xml
	 * @return XmlToolBox
	 */
	protected function makeMenu($xml)
	{
		$slsXml = $this->_generic->getCoreXML('sls');
		
		$xml->startTag('Actions');
			$xml->startTag("Action");
				$xml->addFullTag("name", "Dashboard <span class='version'>(sls v".$slsXml->getTag("//sls_configs/version").")</span>", true);
				$xml->addFullTag("link", $this->_generic->getFullPath('SLS_Bo', 'Home'), true);
			$xml->endTag("Action");
			$xml->startTag("Action");
				$xml->addFullTag("name", "Controllers & Actions", true);
				$xml->addFullTag("link", $this->_generic->getFullPath('SLS_Bo', 'Controllers'), true);
				$xml->startTag('sub');
					$xml->addFullTag("name", "Add Controller", true);
					$xml->addFullTag("link", $this->_generic->getFullPath('SLS_Bo', 'AddController'), true);
				$xml->endTag('sub');				
				$xml->startTag('sub');
					$xml->addFullTag("name", "Add Static Controller", true);
					$xml->addFullTag("link", $this->_generic->getFullPath('SLS_Bo', 'AddStaticController'), true);
				$xml->endTag('sub');
				$xml->startTag('sub');
					$xml->addFullTag("name", "Add Component Controller", true);
					$xml->addFullTag("link", $this->_generic->getFullPath('SLS_Bo', 'AddComponentController'), true);
				$xml->endTag('sub');
			$xml->endTag("Action");
			$xml->startTag("Action");
				$xml->addFullTag("name", "Models", true);
				$xml->addFullTag("link", $this->_generic->getFullPath('SLS_Bo', 'Models'), true);
				$xml->startTag('sub');
					$xml->addFullTag("name", "Generate Models", true);
					$xml->addFullTag("link", $this->_generic->getFullPath('SLS_Bo', 'GenerateModels'), true);
				$xml->endTag('sub');
			$xml->endTag("Action");
			$xml->startTag("Action");
				$xml->addFullTag("name", "Views", true);
				$xml->addFullTag("link", $this->_generic->getFullPath('SLS_Bo', 'Templates'), true);
				$xml->startTag('sub');
					$xml->addFullTag("name", "Add Template", true);
					$xml->addFullTag("link", $this->_generic->getFullPath('SLS_Bo', 'AddTemplate'), true);					
				$xml->endTag('sub');
				$xml->startTag('sub');
					$xml->addFullTag("name", "Add Generic", true);
					$xml->addFullTag("link", $this->_generic->getFullPath('SLS_Bo', 'AddGeneric'), true);
				$xml->endTag('sub');
			$xml->endTag("Action");
			$xml->startTag("Action");
				$xml->addFullTag("name", "Back-offices", true);
				$xml->addFullTag("link", $this->_generic->getFullPath('SLS_Bo', 'Bo'), true);
				$xml->startTag('sub');
					$xml->addFullTag("name", "Generate Back-office", true);
					$xml->addFullTag("link", $this->_generic->getFullPath('SLS_Bo', 'GenerateBo'), true);
				$xml->endTag('sub');
				$xml->startTag('sub');
					$xml->addFullTag("name", "Back-office rights", true);
					$xml->addFullTag("link", $this->_generic->getFullPath('SLS_Bo', 'ManageRights'), true);
				$xml->endTag('sub');
			$xml->endTag("Action");
			$xml->startTag("Action");
				$xml->addFullTag("name", "Plugins", true);
				$xml->addFullTag("link", $this->_generic->getFullPath('SLS_Bo', 'Plugins'), true);
			$xml->endTag("Action");			
			$xml->startTag("Action");
				$xml->addFullTag("name", "SillySmart Settings", true);
				$xml->addFullTag("link", $this->_generic->getFullPath('SLS_Bo', 'Settings'), true);
				$xml->startTag('sub');
					$xml->addFullTag("name", "Global<br /> Settings", true);
					$xml->addFullTag("link", $this->_generic->getFullPath('SLS_Bo', 'GlobalSettings'), true);
				$xml->endTag('sub');
				$xml->startTag('sub');
					$xml->addFullTag("name", "Databases<br /> Settings", true);
					$xml->addFullTag("link", $this->_generic->getFullPath('SLS_Bo', 'DataBaseSettings'), true);
				$xml->endTag('sub');				
				$xml->startTag('sub');
					$xml->addFullTag("name", "SMTP Email<br /> Settings", true);
					$xml->addFullTag("link", $this->_generic->getFullPath('SLS_Bo', 'MailSettings'), true);
				$xml->endTag('sub');
				$xml->startTag('sub');
					$xml->addFullTag("name", "Personnal<br /> Settings", true);
					$xml->addFullTag("link", $this->_generic->getFullPath('SLS_Bo', 'ProjectSettings'), true);
				$xml->endTag('sub');
				$xml->startTag('sub');
					$xml->addFullTag("name", "JS / Ajax<br /> Settings", true);
					$xml->addFullTag("link", $this->_generic->getFullPath('SLS_Bo', 'JSSettings'), true);
				$xml->endTag('sub');
			$xml->endTag("Action");
			$xml->startTag("Action");
				$xml->addFullTag("name", "Production Tools", true);
				$xml->addFullTag("link", $this->_generic->getFullPath('SLS_Bo', 'SlsSettings'), true);
				$xml->startTag('sub');
					$xml->addFullTag("name", "Production<br /> Settings", true);
					$xml->addFullTag("link", $this->_generic->getFullPath('SLS_Bo', 'ProdSettings'), true);
				$xml->endTag('sub');
				$xml->startTag('sub');
					$xml->addFullTag("name", "Compressor /<br /> Uncompressor", true);
					$xml->addFullTag("link", $this->_generic->getFullPath('SLS_Bo', 'Compressor'), true);
				$xml->endTag('sub');
				$xml->startTag('sub');
					$xml->addFullTag("name", "Configs<br /> Deployment", true);
					$xml->addFullTag("link", $this->_generic->getFullPath('SLS_Bo', 'ProductionDeployment'), true);
				$xml->endTag('sub');
			$xml->endTag("Action");
			$xml->startTag("Action");
				$xml->addFullTag("name", "Multilanguage", true);
				$xml->addFullTag("link", $this->_generic->getFullPath('SLS_Bo', 'Langs'), true);
				$xml->startTag('sub');
					$xml->addFullTag("name", "Add Lang", true);
					$xml->addFullTag("link", $this->_generic->getFullPath('SLS_Bo', 'AddLang'), true);
				$xml->endTag('sub');
			$xml->endTag("Action");
			$xml->startTag("Action");
				$xml->addFullTag("name", "Logs", true);
				$xml->addFullTag("link", $this->_generic->getFullPath('SLS_Bo', 'LogsMenu'), true);
				$xml->startTag('sub');
					$xml->addFullTag("name", "Monitoring Logs", true);
					$xml->addFullTag("link", $this->_generic->getFullPath('SLS_Bo', 'LogsM'), true);
				$xml->endTag('sub');
				$xml->startTag('sub');
					$xml->addFullTag("name", "Production Logs", true);
					$xml->addFullTag("link", $this->_generic->getFullPath('SLS_Bo', 'Logs'), true);
				$xml->endTag('sub');
				$xml->startTag('sub');
					$xml->addFullTag("name", "Mail Logs", true);
					$xml->addFullTag("link", $this->_generic->getFullPath('SLS_Bo', 'LogsMail'), true);
				$xml->endTag('sub');
			$xml->endTag("Action");
			$xml->startTag("Action");
				$xml->addFullTag("name", "Sitemap", true);
				$xml->addFullTag("link", $this->_generic->getFullPath('SLS_Bo', 'GenerateSiteMap'), true);
			$xml->endTag("Action");
			/*$xml->startTag("Action");
				$xml->addFullTag("name", "Update SillySmart", true);
				$xml->addFullTag("link", $this->_generic->getFullPath('SLS_Bo', 'Updates'), true);
			$xml->endTag("Action");*/			
			$xml->startTag("Action");
				$xml->addFullTag("name", "Reset SillySmart", true);
				$xml->addFullTag("link", $this->_generic->getFullPath('SLS_Bo', 'ResetSLS'), true);
			$xml->endTag("Action");
		$xml->endTag('Actions');
		return $xml;
	}
	
	/**
	 * Check if the request is done by a authentificated people
	 *
	 * @return array or false
	 */
	protected function hasAuthorative()
	{
		$session = $this->_generic->getObjectSession();
		$controllers = $this->_generic->getControllersXML();
		$arrayUser = array();	
		$token = $this->_http->getParam('token');
		
		$sessionToken = substr(substr(sha1($this->_generic->getSiteConfig("privateKey")),12,31).substr(sha1($this->_generic->getSiteConfig("privateKey")),4,11),6);
		
		if ($session->getParam('SLS_SESSION_VALID_'.$sessionToken) == 'true' || ($_SERVER["REMOTE_ADDR"] == $_SERVER["SERVER_ADDR"] && $token == sha1(substr($this->_generic->getSiteConfig("privateKey"), 0, 3).substr($this->_generic->getSiteConfig("privateKey"), strlen($this->_generic->getSiteConfig("privateKey"))-3))))
		{
			$arrayUser['user'] = $session->getParam('SLS_SESSION_USER_'.$sessionToken);
			$arrayUser['pass'] = $session->getParam('SLS_SESSION_PASS_'.$sessionToken);
			$arrayUser['level'] = $session->getParam('SLS_SESSION_LEVEL_'.$sessionToken);
			return $arrayUser;
		}
		else 
		{
			$this->_generic->redirect(array_shift($controllers->getTags("//controllers/controller[@name='SLS_Bo']/controllerLangs/controllerLang"))."/".array_shift($controllers->getTags("//controllers/controller[@name='SLS_Bo']/scontrollers/scontroller[@name='Index']/scontrollerLangs/scontrollerLang")));			
		}
	}
	
	/**
	 * Logout current admin
	 * 
	 */
	protected function logout()
	{
		$session = $this->_generic->getObjectSession();
		$controllers = $this->_generic->getControllersXML();		
		$token = $this->_http->getParam('token');
		
		$sessionToken = substr(substr(sha1($this->_generic->getSiteConfig("privateKey")),12,31).substr(sha1($this->_generic->getSiteConfig("privateKey")),4,11),6);
		
		if ($session->getParam('SLS_SESSION_VALID_'.$sessionToken) == 'true' || ($_SERVER["REMOTE_ADDR"] == $_SERVER["SERVER_ADDR"] && $token == sha1(substr($this->_generic->getSiteConfig("privateKey"), 0, 3).substr($this->_generic->getSiteConfig("privateKey"), strlen($this->_generic->getSiteConfig("privateKey"))-3))))
		{
			$session->delParam('SLS_SESSION_VALID_'.$sessionToken);
			$session->delParam('SLS_SESSION_USER_'.$sessionToken);
			$session->delParam('SLS_SESSION_PASS_'.$sessionToken);
			$session->delParam('SLS_SESSION_LEVEL_'.$sessionToken);
			$session->delParam("SLS_BO_VALID_".$sessionToken);
	        $session->delParam("SLS_BO_USER_".$sessionToken);
	        $session->delParam("SLS_BO_USER");
	        $session->delParam("ckfinderAuthorized");
			$this->_generic->redirect(array_shift($controllers->getTags("//controllers/controller[@name='SLS_Bo']/controllerLangs/controllerLang"))."/".array_shift($controllers->getTags("//controllers/controller[@name='SLS_Bo']/scontrollers/scontroller[@name='Index']/scontrollerLangs/scontrollerLang")));
		}
		else 
		{
			$this->_generic->redirect(array_shift($controllers->getTags("//controllers/controller[@name='SLS_Bo']/controllerLangs/controllerLang"))."/".array_shift($controllers->getTags("//controllers/controller[@name='SLS_Bo']/scontrollers/scontroller[@name='Index']/scontrollerLangs/scontrollerLang")));			
		}
	}
	
	/**
	 * Return all the user models
	 *
	 * @return array list of all models
	 */
	protected function getAllModels()
	{
		// Get all models
		$models = array();
		$handle = opendir($this->_generic->getPathConfig("models"));
		while (false !== ($file = readdir($handle)))					
			if (!is_dir($this->_generic->getPathConfig("models").$file) && substr($file, 0, 1) != ".") 			
			{
				$modelExploded = explode(".",$file);
				array_push($models,strtolower($modelExploded[0]).".".$modelExploded[1]);
			}
		return $models;
	}
	
	/**
	 * If action bo already exist
	 *
	 * @param string $model the model to check
	 * @param string $alias the alias of the db
	 * @return bool true if already exist, else false
	 */
	protected function boActionExist($model,$alias)
	{		
		$controllersXML = $this->_generic->getControllersXML();
		$test = array_shift($controllersXML->getTags("//controllers/controller[@isBo='true']/scontrollers/scontroller[@name='List".ucfirst($alias)."_".SLS_String::tableToClass($model)."']"));		
		return (empty($test)) ? false : true;
	}
	
	/**
	 * Get all bo actions for one model
	 *
	 * @param string $model the model to check
	 * @param string $alias the alias of the db
	 * @return array $actions the list of bo actions
	 */
	protected function getActionsBo($model,$alias)
	{
		$actions = array();
		$controllersXML = $this->_generic->getControllersXML();
		
		$list = array_shift($controllersXML->getTags("//controllers/controller[@isBo='true']/scontrollers/scontroller[@name='List".ucfirst($alias)."_".SLS_String::tableToClass($model)."']"));
		if (!empty($list))
			array_push($actions,"List".ucfirst($alias)."_".SLS_String::tableToClass($model));		
		$add = array_shift($controllersXML->getTags("//controllers/controller[@isBo='true']/scontrollers/scontroller[@name='Add".ucfirst($alias)."_".SLS_String::tableToClass($model)."']"));
		if (!empty($add))
			array_push($actions,"Add".ucfirst($alias)."_".SLS_String::tableToClass($model));
		$edit = array_shift($controllersXML->getTags("//controllers/controller[@isBo='true']/scontrollers/scontroller[@name='Modify".ucfirst($alias)."_".SLS_String::tableToClass($model)."']"));
		if (!empty($edit))
			array_push($actions,"Modify".ucfirst($alias)."_".SLS_String::tableToClass($model));
		$del = array_shift($controllersXML->getTags("//controllers/controller[@isBo='true']/scontrollers/scontroller[@name='Delete".ucfirst($alias)."_".SLS_String::tableToClass($model)."']"));
		if (!empty($del))
			array_push($actions,"Delete".ucfirst($alias)."_".SLS_String::tableToClass($model));
		$clone = array_shift($controllersXML->getTags("//controllers/controller[@isBo='true']/scontrollers/scontroller[@name='Clone".ucfirst($alias)."_".SLS_String::tableToClass($model)."']"));
		if (!empty($clone))
			array_push($actions,"Clone".ucfirst($alias)."_".SLS_String::tableToClass($model));
		$email = array_shift($controllersXML->getTags("//controllers/controller[@isBo='true']/scontrollers/scontroller[@name='Email".ucfirst($alias)."_".SLS_String::tableToClass($model)."']"));
		if (!empty($email))
			array_push($actions,"Email".ucfirst($alias)."_".SLS_String::tableToClass($model));
		return $actions;
	}	
	
	/**
	 * Create a new action list in bo
	 *
	 * @param string $controller generic controller name
	 * @param string $model the model you want to create bo	 
	 * @param string $alias the alias of the db
	 * @param array $columns the columns list you want to display
	 * @param array $filters the columns list you want to filters
	 * @param array $group the column on which you want to group by
	 * @param array $order the column & direction of order
	 * @param array $limit the bounds limit
	 * @param string $join the natural join table
	 * @param array $actions list of actions you want to map with action list (default: all)	 
	 */
	protected function createActionBoList($controller,$model,$alias,$columns=array(),$filters=array(),$group=array(),$order=array(),$limit=array(),$join="",$actions=array("add"=>true,"modify"=>true,"delete"=>true,"clone"=>true,"email"=>true))
	{		
		$langs = $this->_generic->getObjectLang()->getSiteLangs();
		
		$params = array(0 => array("key" 	=> "reload",
				  				   "value" 	=> "true"),
				  		1 => array("key" 	=> "Controller",
				  				   "value" 	=> $controller),
					 	2 => array("key" 	=> "actionName",
				  				   "value" 	=> "List".ucfirst($alias)."_".SLS_String::tableToClass($model)),
	  				   	3 => array("key" 	=> "token",
				  				   "value" 	=> sha1(substr($this->_generic->getSiteConfig("privateKey"), 0, 3).substr($this->_generic->getSiteConfig("privateKey"), strlen($this->_generic->getSiteConfig("privateKey"))-3))),
				  		4 => array("key"	=> "indexes",
				  				   "value"	=> "noindex,nofollow")				  				   
					    );
		foreach($langs as $lang)
		{
			$tmpParam = array("key" 	=> $lang."-action",
							  "value" 	=> "List".ucfirst($alias)."_".SLS_String::tableToClass($model)."_".$lang);
			$tmpTitle = array("key" 	=> $lang."-title",
							  "value" 	=> $model."_listing");
			array_push($params,$tmpParam);
			array_push($params,$tmpTitle);
		}
		
		file_get_contents($this->_generic->getFullPath("SLS_Bo",
													  "AddAction",
													  $params,
													  true));
		$source = file_get_contents($this->_generic->getPathConfig("actionsControllers").$controller."/List".ucfirst($alias)."_".SLS_String::tableToClass($model).".controller.php");
		
		$this->_generic->useModel($model,$alias,"user");
		$class = ucfirst($alias)."_".SLS_String::tableToClass($model);
		$object = new $class();
		$properties = $object->getParams();
		
		// Columns to display
		if (empty($columns))
		{
			$columnsD = 'array(';
			$i=0;
			foreach($properties as $key => $value)
			{
				$tmp = array("column" => $key, "description" => "");
				if ($i>0)
					$columnsD .= t(2).'                      ';
				$columnsD .= ''.$i.' => array("column" => "'.$key.'", "description" => "")';
				if ($i<(count($properties)-1))
					$columnsD .= ','."\n";
				$i++;
			}
			$columnsD .= ');';
		}
		else
		{
			$columnsD = 'array(';
			$i=0;
			foreach($columns as $key)
			{
				$tmp = array("column" => $key, "description" => "");
				if ($i>0)
					$columnsD .= t(2).'                      ';
				$columnsD .= ''.$i.' => array("column" => "'.$key.'", "description" => "")';
				if ($i<(count($columns)-1))
					$columnsD .= ','."\n";
				$i++;
			}
			$columnsD .= ');';
		}
		// /Columns to display
		
		// Columns to filter
		if (empty($filters))
		{
			$columnsF = 'array(';
			$i=0;
			foreach($properties as $key => $value)
			{
				$tmp = array("column" => $key, "description" => "");
				if ($i>0)
					$columnsF .= t(2).'                      ';
				$columnsF .= ''.$i.' => array("column" => "'.$key.'", "description" => "")';
				if ($i<(count($properties)-1))
					$columnsF .= ','."\n";
				$i++;
			}
			$columnsF .= ');';
		}
		else
		{
			$columnsF = 'array(';
			$i=0;
			foreach($filters as $key)
			{
				$tmp = array("column" => $key, "description" => "");
				if ($i>0)
					$columnsF .= t(2).'                      ';
				$columnsF .= ''.$i.' => array("column" => "'.$key.'", "description" => "")';
				if ($i<(count($filters)-1))
					$columnsF .= ','."\n";
				$i++;
			}
			$columnsF .= ');';
		}
		// /Columns to filter	
		
		$controllersXML = $this->_generic->getControllersXML();
		$controllerBo = array_shift($controllersXML->getTags("//controllers/controller[@isBo='true']/@name"));
		
		$action = 	t(2).'// Params'."\n".
					t(2).'$arrayFilters = '.$columnsF.''."\n".
					t(2).'$arrayColumns = '.$columnsD.''."\n".
					t(2).'// /Params'."\n".
					t(2).''."\n".
					t(2).'// Check account rights'."\n".
					t(2).'$right = SLS_BoRights::isAuthorized("read","'.ucfirst($alias).'_'.ucfirst($model).'",$this->_generic->getActionId());'."\n".
					t(2).'if ($right != 1)'."\n".
					t(3).'$this->_generic->redirect("'.$controllerBo.'/Connection.sls");'."\n".
					t(2).'// /Check account rights'."\n".
					t(2).''."\n".
					t(2).'$boListing = new SLS_BoListing($this,"'.$model.'","'.$alias.'");'."\n".
					t(2).'$boListing->setCurrentUrl("'.$controller.'","List'.ucfirst($alias)."_".SLS_String::tableToClass($model).'");'."\n".
					t(2).'$boListing->setAllowedFilters($arrayFilters);'."\n".
					t(2).'$boListing->setColumnsToShow($arrayColumns);'."\n";
		
		// Order
		if (!empty($order))
		{
			$action .= t(2).'$boListing->setDefaultOrder("'.$order["column"].'","'.$order["order"].'");'."\n";
		}
		// /Order
		
		// Group by
		if (!empty($group))
		{
			$strGroup = "array(";
			$first = true;
			foreach($group as $col)
			{
				if (!$first)
					$strGroup .= ", ";
				$strGroup .= "'".$col."'";
				$first = false;
			}
			$strGroup .= ")";
			$action .= t(2).'$boListing->setDefaultGroupBy('.$strGroup.');'."\n";
		}
		// /Group by
		
		// Limit
		if (!empty($limit))
		{
			$action .= t(2).'$boListing->setDefaultLimit("'.$limit["start"].'","'.$limit["length"].'");'."\n";
		}
		// /Limit
		
		// Join
		if (!empty($join))
		{
			$action .= t(2).'$boListing->setJoin(array('.$join.'));'."\n";			
		}
		// /Join
		
		// Actions
		if ($actions["delete"])
		{			
			$action .=  t(2).'if (SLS_BoRights::boActionExist("'.$alias.'","'.$model.'","Delete") && SLS_BoRights::isAuthorized("delete","'.ucfirst($alias).'_'.ucfirst($model).'"))'."\n";
			$action .=		t(3).'$boListing->addActionDelete("'.$controller.'","Delete'.ucfirst($alias)."_".SLS_String::tableToClass($model).'");'."\n";
		}
		if ($actions["modify"])
		{
			$action .=  t(2).'if (SLS_BoRights::boActionExist("'.$alias.'","'.$model.'","Modify") && SLS_BoRights::isAuthorized("edit","'.ucfirst($alias).'_'.ucfirst($model).'"))'."\n";
			$action .=		t(3).'$boListing->addActionModify("'.$controller.'","Modify'.ucfirst($alias)."_".SLS_String::tableToClass($model).'");'."\n";
		}
		if ($actions["add"])
		{
			$action .=  t(2).'if (SLS_BoRights::boActionExist("'.$alias.'","'.$model.'","Add") && SLS_BoRights::isAuthorized("add","'.ucfirst($alias).'_'.ucfirst($model).'"))'."\n";
			$action .=		t(3).'$boListing->addActionAdd("'.$controller.'","Add'.ucfirst($alias)."_".SLS_String::tableToClass($model).'");'."\n";
		}
		if ($actions["clone"])
		{
			$action .=  t(2).'if (SLS_BoRights::boActionExist("'.$alias.'","'.$model.'","Clone") && SLS_BoRights::isAuthorized("clone","'.ucfirst($alias).'_'.ucfirst($model).'"))'."\n";
			$action .=		t(3).'$boListing->addActionClone("'.$controller.'","Clone'.ucfirst($alias)."_".SLS_String::tableToClass($model).'");'."\n";
		}
		if ($actions["email"])
		{
			$action .=  t(2).'if (SLS_BoRights::boActionExist("'.$alias.'","'.$model.'","Email") && SLS_BoRights::isAuthorized("email","'.ucfirst($alias).'_'.ucfirst($model).'"))'."\n";
			$action .=		t(3).'$boListing->addActionEmail("'.$controller.'","Email'.ucfirst($alias)."_".SLS_String::tableToClass($model).'");'."\n";
		}
		// /Actions
				
		$action .=	t(2).'$boListing->constructList();'."\n".
					t(2).'$xml = $this->getXML();'."\n".
					t(2).'$boActions = SLS_BoRights::getDistinctActions();'."\n".
        		    t(2).'$xml->startTag("bo_actions");'."\n".
        		    t(2).'for($i=0 ; $i<$count=count($boActions) ; $i++)'."\n".
        		    t(2).'{'."\n".
	        		    t(3).'$xml->startTag("bo_action");'."\n".
	        		    t(3).'foreach($boActions[$i] as $key => $value)'."\n".
	        		    	t(4).'$xml->addFullTag($key,$value,true);'."\n".
	        		    t(3).'$xml->endTag("bo_action");'."\n".
        		    t(2).'}'."\n".
        		    t(2).'$xml->endTag("bo_actions");'."\n\n".
        		    t(2).'// Export'."\n".
			        t(2).'$http = $this->_generic->getObjectHttpRequest();'."\n".
			        t(2).'$controllersXML = $this->_generic->getControllersXML();'."\n".
					t(2).'$controller = array_shift($controllersXML->getTags("//controllers/controller[@isBo=\'true\']/@name"));'."\n".
					t(2).'$controllers = $this->_generic->getTranslatedController($controller,"Export");'."\n".
					t(2).'$column = ($http->getParam("column") == "") ? "|sls_empty|" : $http->getParam("column");'."\n".
					t(2).'$order = ($http->getParam("order") == "") ? "|sls_empty|" : $http->getParam("order");'."\n".
					t(2).'$group_filter = ($http->getParam("group_filter") == "") ? "|sls_empty|" : $http->getParam("group_filter");'."\n".		
			        t(2).'$queryString = $controllers["protocol"]."://".$this->_generic->getSiteConfig("domainName")."/".$controllers["controller"]."/".$controllers["scontroller"]."/column/".$column."/order/".$order;'."\n".
			        t(2).'foreach($http->getParams() as $key => $value)'."\n".
						t(3).'if (SLS_String::startsWith($key,"filter_"))'."\n".
						t(3).'{'."\n".
							t(4).'if (empty($value))'."\n".
								t(5).'$value = "|sls_empty|";'."\n".
							t(4).'$queryString .= "/".$key."/".$value;'."\n".
						t(3).'}'."\n".
					t(2).'for($i=0 ; $i<$count=count($arrayColumns) ; $i++)'."\n".
						t(3).'$queryString .= "/Export_Column_".$i."/".$arrayColumns[$i]["column"];'."\n".
					t(2).'$queryString .= "/Export_Model/'.$object->getTable().'/Export_Db/'.$alias.'";'."\n";
		if (!empty($join))
			$action .= t(2).'$queryString .= "/Export_Join/'.str_replace('"','',$join).'";'."\n";			
		$action	.=	t(2).'$xml->addFullTag("url_export",$queryString,true);'."\n".
			        t(2).'// /Export'."\n\n".
			        t(2).'// Referrer'."\n".
        			t(2).'$http = $this->_generic->getObjectHttpRequest();'."\n".
					t(2).'$params = $http->getParams();'."\n".
					t(2).'$strPost = "";'."\n".
					t(2).'foreach($params as $key => $value)'."\n".
						t(3).'if ($key != "mode" && $key != "smode" && !empty($value))'."\n".
							t(4).'$strPost .= $key."/".$value."/";'."\n".
					t(2).'$this->_generic->getObjectSession()->setParam("SLS_PREVIOUS_POST_List'.ucfirst($alias)."_".SLS_String::tableToClass($model).'",$strPost);'."\n".
			        t(2).'// /Referrer'."\n\n".
        		    t(2).'$this->saveXML($xml);'."\n";
       	
		$source = substr($source,0,strpos($source,"action()")+8)."\n".
				  t(1).'{'."\n".
				  $action.
				  t(1).'}'."\n".
				  '}'."\n".
				  '?>';
		file_put_contents($this->_generic->getPathConfig("actionsControllers").$controller."/List".ucfirst($alias)."_".SLS_String::tableToClass($model).".controller.php",$source);
		$sourceXsl = '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" xmlns="http://www.w3.org/1999/xhtml">'."\n".
					 t(1).'<xsl:template name="List'.ucfirst($alias)."_".SLS_String::tableToClass($model).'">'."\n".
						 t(2).'<xsl:call-template name="BoMenu" />'."\n".
						 t(2).'<xsl:call-template name="BoListing" />'."\n".
					 t(1).'</xsl:template>'."\n".
					 '</xsl:stylesheet>';
		file_put_contents($this->_generic->getPathConfig("viewsBody").$controller."/List".ucfirst($alias)."_".SLS_String::tableToClass($model).".xsl",$sourceXsl);
	}
	
	/**
	 * Create a new action add in bo
	 *
	 * @param string $controller generic controller name
	 * @param string $model the model you want to create bo
	 * @param string $alias the alias of the db
	 */
	protected function createActionBoAdd($controller,$model,$alias)
	{
		$langs = $this->_generic->getObjectLang()->getSiteLangs();
		
		$params = array(0 => array("key" 	=> "reload",
				  				   "value" 	=> "true"),
				  		1 => array("key" 	=> "Controller",
				  				   "value" 	=> $controller),
					 	2 => array("key" 	=> "actionName",
				  				   "value" 	=> "Add".ucfirst($alias)."_".SLS_String::tableToClass($model)),
				  		3 => array("key"	=> "token",
				  					"value"	=> sha1(substr($this->_generic->getSiteConfig("privateKey"), 0, 3).substr($this->_generic->getSiteConfig("privateKey"), strlen($this->_generic->getSiteConfig("privateKey"))-3))),
				  		4 => array("key"	=> "indexes",
				  				   "value"	=> "noindex,nofollow")
					    );
		foreach($langs as $lang)
		{
			$tmpParam = array("key" 	=> $lang."-action",
							  "value" 	=> "Add".ucfirst($alias)."_".SLS_String::tableToClass($model)."_".$lang);
			$tmpTitle = array("key" 	=> $lang."-title",
							  "value" 	=> $model."_adding");
			array_push($params,$tmpParam);
			array_push($params,$tmpTitle);
		}
		file_get_contents($this->_generic->getFullPath("SLS_Bo",
													  "AddAction",
													  $params,
													  true));
		$source = file_get_contents($this->_generic->getPathConfig("actionsControllers").$controller."/Add".ucfirst($alias)."_".SLS_String::tableToClass($model).".controller.php");
		
		
		$action = 	t(2).'$xml = $this->getXML();'."\n".
					t(2).'$boActions = SLS_BoRights::getDistinctActions();'."\n".
        		    t(2).'$xml->startTag("bo_actions");'."\n".
        		    t(2).'for($i=0 ; $i<$count=count($boActions) ; $i++)'."\n".
        		    t(2).'{'."\n".
	        		    t(3).'$xml->startTag("bo_action");'."\n".
	        		    	t(4).'foreach($boActions[$i] as $key => $value)'."\n".
	        		    		t(5).'$xml->addFullTag($key,$value,true);'."\n".
	        		    t(3).'$xml->endTag("bo_action");'."\n".
        		    t(2).'}'."\n".
        		    t(2).'$xml->endTag("bo_actions");'."\n".
					t(2).''."\n".
					t(2).'// Check account rights'."\n".
					t(2).'$right = SLS_BoRights::isAuthorized("add","'.ucfirst($alias).'_'.$model.'",$this->_generic->getActionId());'."\n".
					t(2).'if ($right == -1)'."\n".
						t(3).'$this->_generic->redirect("'.$controller.'/Connection.sls");'."\n".
					t(2).'else if ($right == 0)'."\n".					
						t(3).'$this->_generic->redirect("'.$controller.'/List'.ucfirst($alias)."_".SLS_String::tableToClass($model).'.sls");'."\n".					
					t(2).'// /Check account rights'."\n".
					t(2).''."\n".
					t(2).'$bo = new SLS_BoAdd($this,"'.$model.'","'.$alias.'",$xml);'."\n".					
					t(2).'$bo->setUrlToRedirect($this->_generic->getFullPath("'.$controller.'","List'.ucfirst($alias)."_".SLS_String::tableToClass($model).'"));'."\n".
					t(2).'$this->saveXML($bo->constructAdd());'."\n";
		$source = substr($source,0,strpos($source,"action()")+8)."\n".
				  t(1).'{'."\n".
				  $action.
				  t(1).'}'."\n".
				  '}'."\n".
				  '?>';
		file_put_contents($this->_generic->getPathConfig("actionsControllers").$controller."/Add".ucfirst($alias)."_".SLS_String::tableToClass($model).".controller.php",$source);
		$sourceXsl = '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" xmlns="http://www.w3.org/1999/xhtml">'."\n".
					 t(1).'<xsl:template name="Add'.ucfirst($alias)."_".SLS_String::tableToClass($model).'">'."\n".
						 t(2).'<xsl:call-template name="BoMenu" />'."\n".
						 t(2).'<xsl:call-template name="BoAdd" />'."\n".
					 t(1).'</xsl:template>'."\n".
					 '</xsl:stylesheet>';
		file_put_contents($this->_generic->getPathConfig("viewsBody").$controller."/Add".ucfirst($alias)."_".SLS_String::tableToClass($model).".xsl",$sourceXsl);
	}
	
	/**
	 * Create a new action modify in bo
	 *
	 * @param string $controller generic controller name
	 * @param string $model the model you want to create bo	
	 * @param string $alias the alias of the db 
	 */
	protected function createActionBoModify($controller,$model,$alias)
	{
		$langs = $this->_generic->getObjectLang()->getSiteLangs();
		
		$params = array(0 => array("key" 	=> "reload",
				  				   "value" 	=> "true"),
				  		1 => array("key" 	=> "Controller",
				  				   "value" 	=> $controller),
					 	2 => array("key" 	=> "actionName",
				  				   "value" 	=> "Modify".ucfirst($alias)."_".SLS_String::tableToClass($model)),
				  		3 => array("key"	=> "token",
				  					"value"	=> sha1(substr($this->_generic->getSiteConfig("privateKey"), 0, 3).substr($this->_generic->getSiteConfig("privateKey"), strlen($this->_generic->getSiteConfig("privateKey"))-3))),
				  		4 => array("key"	=> "indexes",
				  				   "value"	=> "noindex,nofollow")				  			
					    );
		foreach($langs as $lang)
		{
			$tmpParam = array("key" 	=> $lang."-action",
							  "value" 	=> "Modify".ucfirst($alias)."_".SLS_String::tableToClass($model)."_".$lang);
			$tmpTitle = array("key" 	=> $lang."-title",
							  "value" 	=> $model."_modifying");
			array_push($params,$tmpParam);
			array_push($params,$tmpTitle);
		}
		file_get_contents($this->_generic->getFullPath("SLS_Bo",
													  "AddAction",
													  $params,
													  true));
		$source = file_get_contents($this->_generic->getPathConfig("actionsControllers").$controller."/Modify".ucfirst($alias)."_".SLS_String::tableToClass($model).".controller.php");
		
		
		$action = 	t(2).'$xml = $this->getXML();'."\n".
					t(2).'$boActions = SLS_BoRights::getDistinctActions();'."\n".
        		    t(2).'$xml->startTag("bo_actions");'."\n".
        		    t(2).'for($i=0 ; $i<$count=count($boActions) ; $i++)'."\n".
        		    t(2).'{'."\n".
        		    	t(3).'$xml->startTag("bo_action");'."\n".
        		    		t(4).'foreach($boActions[$i] as $key => $value)'."\n".
        		    			t(5).'$xml->addFullTag($key,$value,true);'."\n".
        		    	t(3).'$xml->endTag("bo_action");'."\n".
        		    t(2).'}'."\n".
        		    t(2).'$xml->endTag("bo_actions");'."\n\n".
					t(2).'// Check account rights'."\n".
					t(2).'$right = SLS_BoRights::isAuthorized("edit","'.ucfirst($alias).'_'.$model.'",$this->_generic->getActionId());'."\n".
					t(2).'if ($right == -1)'."\n".
						t(3).'$this->_generic->redirect("'.$controller.'/Connection.sls");'."\n".
					t(2).'else if ($right == 0)'."\n".					
						t(3).'$this->_generic->redirect("'.$controller.'/List'.ucfirst($alias)."_".SLS_String::tableToClass($model).'.sls");'."\n".					
					t(2).'// /Check account rights'."\n".
					t(2).''."\n".
					t(2).'$bo = new SLS_BoEdit($this,"'.$model.'","'.$alias.'",$xml);'."\n".
					t(2).'$bo->setUrlToRedirect("'.$controller.'","List'.ucfirst($alias)."_".SLS_String::tableToClass($model).'");'."\n".
					t(2).'$this->saveXML($bo->constructEdit());'."\n";
		$source = substr($source,0,strpos($source,"action()")+8)."\n".
				  t(1).'{'."\n".
				  $action.
				  t(1).'}'."\n".
				  '}'."\n".
				  '?>';
		file_put_contents($this->_generic->getPathConfig("actionsControllers").$controller."/Modify".ucfirst($alias)."_".SLS_String::tableToClass($model).".controller.php",$source);
		$sourceXsl = '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" xmlns="http://www.w3.org/1999/xhtml">'."\n".
					 t(1).'<xsl:template name="Modify'.ucfirst($alias)."_".SLS_String::tableToClass($model).'">'."\n".
						 t(2).'<xsl:call-template name="BoMenu" />'."\n".
						 t(2).'<xsl:call-template name="BoEdit" />'."\n".
					 t(1).'</xsl:template>'."\n".
					 '</xsl:stylesheet>';
		file_put_contents($this->_generic->getPathConfig("viewsBody").$controller."/Modify".ucfirst($alias)."_".SLS_String::tableToClass($model).".xsl",$sourceXsl);
	}
	
	/**
	 * Create a new action delete in bo
	 *
	 * @param string $controller generic controller name
	 * @param string $model the model you want to create bo	 
	 * @param string $alias the alias of the db
	 */
	protected function createActionBoDelete($controller,$model,$alias)
	{
		$langs = $this->_generic->getObjectLang()->getSiteLangs();
		
		$params = array(0 => array("key" 	=> "reload",
				  				   "value" 	=> "true"),
				  		1 => array("key" 	=> "Controller",
				  				   "value" 	=> $controller),
					 	2 => array("key" 	=> "actionName",
				  				   "value" 	=> "Delete".ucfirst($alias)."_".SLS_String::tableToClass($model)),
				  		3 => array("key"	=> "token",
				  				   "value"	=> sha1(substr($this->_generic->getSiteConfig("privateKey"), 0, 3).substr($this->_generic->getSiteConfig("privateKey"), strlen($this->_generic->getSiteConfig("privateKey"))-3))),
				  		4 => array("key"	=> "indexes",
				  				   "value"	=> "noindex,nofollow")				  			
					    );
		foreach($langs as $lang)
		{
			$tmpParam = array("key" 	=> $lang."-action",
							  "value" 	=> "Delete".ucfirst($alias)."_".SLS_String::tableToClass($model)."_".$lang);
			$tmpTitle = array("key" 	=> $lang."-title",
							  "value" 	=> $model."_deleting");
			array_push($params,$tmpParam);
			array_push($params,$tmpTitle);
		}
		file_get_contents($this->_generic->getFullPath("SLS_Bo",
													  "AddAction",
													  $params,
													  true));
		$source = file_get_contents($this->_generic->getPathConfig("actionsControllers").$controller."/Delete".ucfirst($alias)."_".SLS_String::tableToClass($model).".controller.php");
		
		
		$action = 	t(2).'// Check account rights'."\n".
					t(2).'$right = SLS_BoRights::isAuthorized("delete","'.ucfirst($alias).'_'.$model.'",$this->_generic->getActionId());'."\n".
					t(2).'if ($right == -1)'."\n".
						t(3).'$this->_generic->redirect("'.$controller.'/Connection.sls");'."\n".
					t(2).'else if ($right == 0)'."\n".					
						t(3).'$this->_generic->redirect("'.$controller.'/List'.ucfirst($alias)."_".SLS_String::tableToClass($model).'.sls");'."\n".					
					t(2).'// /Check account rights'."\n".
					t(2).''."\n".
					t(2).'$bo = new SLS_BoDelete($this,"'.$model.'","'.$alias.'");'."\n".
					t(2).'$bo->setUrlToRedirect("'.$controller.'","List'.ucfirst($alias)."_".SLS_String::tableToClass($model).'");'."\n".
					t(2).'$this->saveXML($bo->constructDelete());'."\n";
		$source = substr($source,0,strpos($source,"action()")+8)."\n".
				  t(1).'{'."\n".
				  $action.
				  t(1).'}'."\n".
				  '}'."\n".
				  '?>';
		file_put_contents($this->_generic->getPathConfig("actionsControllers").$controller."/Delete".ucfirst($alias)."_".SLS_String::tableToClass($model).".controller.php",$source);
	}
	
	/**
	 * Create a new action clone in bo
	 *
	 * @param string $controller generic controller name
	 * @param string $model the model you want to create bo
	 * @param string $alias the alias of the db
	 */
	protected function createActionBoClone($controller,$model,$alias)
	{
		$langs = $this->_generic->getObjectLang()->getSiteLangs();
		
		$params = array(0 => array("key" 	=> "reload",
				  				   "value" 	=> "true"),
				  		1 => array("key" 	=> "Controller",
				  				   "value" 	=> $controller),
					 	2 => array("key" 	=> "actionName",
				  				   "value" 	=> "Clone".ucfirst($alias)."_".SLS_String::tableToClass($model)),
				  		3 => array("key"	=> "token",
				  					"value"	=> sha1(substr($this->_generic->getSiteConfig("privateKey"), 0, 3).substr($this->_generic->getSiteConfig("privateKey"), strlen($this->_generic->getSiteConfig("privateKey"))-3))),
				  		4 => array("key"	=> "indexes",
				  				   "value"	=> "noindex,nofollow")				  			
					    );
		foreach($langs as $lang)
		{
			$tmpParam = array("key" 	=> $lang."-action",
							  "value" 	=> "Clone".ucfirst($alias)."_".SLS_String::tableToClass($model)."_".$lang);
			$tmpTitle = array("key" 	=> $lang."-title",
							  "value" 	=> $model."_cloning");
			array_push($params,$tmpParam);
			array_push($params,$tmpTitle);
		}
		file_get_contents($this->_generic->getFullPath("SLS_Bo",
													  "AddAction",
													  $params,
													  true));
		$source = file_get_contents($this->_generic->getPathConfig("actionsControllers").$controller."/Clone".ucfirst($alias)."_".SLS_String::tableToClass($model).".controller.php");
		
		
		$action = 	t(2).'$xml = $this->getXML();'."\n".
					t(2).'$boActions = SLS_BoRights::getDistinctActions();'."\n".
        		    t(2).'$xml->startTag("bo_actions");'."\n".
        		    t(2).'for($i=0 ; $i<$count=count($boActions) ; $i++)'."\n".
        		    t(2).'{'."\n".
        		    	t(3).'$xml->startTag("bo_action");'."\n".
        		    		t(4).'foreach($boActions[$i] as $key => $value)'."\n".
        		    			t(5).'$xml->addFullTag($key,$value,true);'."\n".
        		    	t(3).'$xml->endTag("bo_action");'."\n".
        		    t(2).'}'."\n".
        		    t(2).'$xml->endTag("bo_actions");'."\n".
					t(2).''."\n".
					t(2).'// Check account rights'."\n".
					t(2).'$right = SLS_BoRights::isAuthorized("clone","'.ucfirst($alias).'_'.$model.'",$this->_generic->getActionId());'."\n".
					t(2).'if ($right == -1)'."\n".
						t(3).'$this->_generic->redirect("'.$controller.'/Connection.sls");'."\n".
					t(2).'else if ($right == 0)'."\n".					
						t(3).'$this->_generic->redirect("'.$controller.'/List'.ucfirst($alias)."_".SLS_String::tableToClass($model).'.sls");'."\n".					
					t(2).'// /Check account rights'."\n".
					t(2).''."\n".
					t(2).'$bo = new SLS_BoClone($this,"'.$model.'","'.$alias.'",$xml);'."\n".					
					t(2).'$bo->setUrlToRedirect("'.$controller.'","List'.ucfirst($alias)."_".SLS_String::tableToClass($model).'");'."\n".
					t(2).'$this->saveXML($bo->constructClone());'."\n";
		$source = substr($source,0,strpos($source,"action()")+8)."\n".
				  t(1).'{'."\n".
				  $action.
				  t(1).'}'."\n".
				  '}'."\n".
				  '?>';
		file_put_contents($this->_generic->getPathConfig("actionsControllers").$controller."/Clone".ucfirst($alias)."_".SLS_String::tableToClass($model).".controller.php",$source);		
	}
	
	/**
	 * Create a new action email in bo
	 *
	 * @param string $controller generic controller name
	 * @param string $model the model you want to create bo
	 * @param string $alias the alias of the db
	 */
	protected function createActionBoEmail($controller,$model,$alias)
	{
		$langs = $this->_generic->getObjectLang()->getSiteLangs();
		
		$params = array(0 => array("key" 	=> "reload",
				  				   "value" 	=> "true"),
				  		1 => array("key" 	=> "Controller",
				  				   "value" 	=> $controller),
					 	2 => array("key" 	=> "actionName",
				  				   "value" 	=> "Email".ucfirst($alias)."_".SLS_String::tableToClass($model)),
				  		3 => array("key"	=> "token",
				  					"value"	=> sha1(substr($this->_generic->getSiteConfig("privateKey"), 0, 3).substr($this->_generic->getSiteConfig("privateKey"), strlen($this->_generic->getSiteConfig("privateKey"))-3))),
				  		4 => array("key"	=> "indexes",
				  				   "value"	=> "noindex,nofollow")				  			
					    );
		foreach($langs as $lang)
		{
			$tmpParam = array("key" 	=> $lang."-action",
							  "value" 	=> "Email".ucfirst($alias)."_".SLS_String::tableToClass($model)."_".$lang);
			$tmpTitle = array("key" 	=> $lang."-title",
							  "value" 	=> $model."_emailing");
			array_push($params,$tmpParam);
			array_push($params,$tmpTitle);
		}
		file_get_contents($this->_generic->getFullPath("SLS_Bo",
													  "AddAction",
													  $params,
													  true));
		$source = file_get_contents($this->_generic->getPathConfig("actionsControllers").$controller."/Email".ucfirst($alias)."_".SLS_String::tableToClass($model).".controller.php");
		
		
		$action = 	t(2).'$xml = $this->getXML();'."\n".
					t(2).'$boActions = SLS_BoRights::getDistinctActions();'."\n".
        		    t(2).'$xml->startTag("bo_actions");'."\n".
        		    t(2).'for($i=0 ; $i<$count=count($boActions) ; $i++)'."\n".
        		    t(2).'{'."\n".
        		    	t(3).'$xml->startTag("bo_action");'."\n".
        		    		t(4).'foreach($boActions[$i] as $key => $value)'."\n".
        		    			t(5).'$xml->addFullTag($key,$value,true);'."\n".
        		    	t(3).'$xml->endTag("bo_action");'."\n".
        		    t(2).'}'."\n".
        		    t(2).'$xml->endTag("bo_actions");'."\n".
					t(2).''."\n".
					t(2).'// Check account rights'."\n".
					t(2).'$right = SLS_BoRights::isAuthorized("email","'.ucfirst($alias).'_'.$model.'",$this->_generic->getActionId());'."\n".
					t(2).'if ($right == -1)'."\n".
						t(3).'$this->_generic->redirect("'.$controller.'/Connection.sls");'."\n".
					t(2).'else if ($right == 0)'."\n".					
						t(3).'$this->_generic->redirect("'.$controller.'/List'.ucfirst($alias)."_".SLS_String::tableToClass($model).'.sls");'."\n".					
					t(2).'// /Check account rights'."\n".
					t(2).''."\n".
					t(2).'$bo = new SLS_BoEmail($this,"'.$model.'","'.$alias.'");'."\n".
					t(2).'$this->saveXML($bo->constructEmail($xml));'."\n";
		$source = substr($source,0,strpos($source,"action()")+8)."\n".
				  t(1).'{'."\n".
				  $action.
				  t(1).'}'."\n".
				  '}'."\n".
				  '?>';
		file_put_contents($this->_generic->getPathConfig("actionsControllers").$controller."/Email".ucfirst($alias)."_".SLS_String::tableToClass($model).".controller.php",$source);
		$sourceXsl = '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" xmlns="http://www.w3.org/1999/xhtml">'."\n".
					 t(1).'<xsl:template name="Email'.ucfirst($alias)."_".SLS_String::tableToClass($model).'">'."\n".
						 t(2).'<xsl:call-template name="BoMenu" />'."\n".
						 t(2).'<xsl:call-template name="BoEmail" />'."\n".
					 t(1).'</xsl:template>'."\n".
					 '</xsl:stylesheet>';
		file_put_contents($this->_generic->getPathConfig("viewsBody").$controller."/Email".ucfirst($alias)."_".SLS_String::tableToClass($model).".xsl",$sourceXsl);		
	}
	
	/**
	 * Create templates for Bo controller
	 *
	 */
	protected function createBoTemplates()
	{
		$tpl1= '<!--'."\n".
			   '  - Global template for your application'."\n".
			   '  - Don\'t change anything between marked delimiter |||dtd:tagName|||'."\n".
			   '  - Beyond you can add additional headers or/and xhtml structure'."\n".
			   '-->'."\n".
			   '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" xmlns="http://www.w3.org/1999/xhtml">'."\n".
			   t(1).'<xsl:output method="xml" omit-xml-declaration="yes" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" indent="yes" encoding="|||sls:getCharset|||" />'."\n\n".
			   t(1).'<!-- Variable Builder -->'."\n".
			   t(1).'|||sls:buildUrlVars|||'."\n".
			   t(1).'<!-- /Variable Builder -->'."\n\n".			
			   t(1).'<!-- Generic include -->'."\n".
			   t(1).'|||sls:includeActionFileBody|||'."\n".
			   t(1).'|||sls:includeActionFileHeader|||'."\n".
			   t(1).'|||sls:includeStaticsFiles|||'."\n".
			   t(1).'<!-- /Generic include -->'."\n\n".			
			   t(1).'<xsl:template match="root">'."\n".
			       t(2).'<html xml:lang="|||sls:getLanguage|||" lang="|||sls:getLanguage|||">'."\n".
				       t(3).'<head>'."\n\n".
					       t(4).'<!-- Generic headers loading -->'."\n".
					       t(4).'<xsl:call-template name="GenerateMetas" />'."\n".			   
					       t(4).'|||sls:loadActionFileHeader|||'."\n".
					       t(4).'<!-- /Generic headers loading -->'."\n\n".
						   t(4).'<script type="text/javascript">'."\n".
							   t(5).'if (typeof MooTools == "undefined"){'."\n".
							   		t(6).'document.write(unescape("%3Cscript src=\'<xsl:value-of select="$sls_url_js_core_statics" />SLS_Statics_compressed.js\'type=\'text/javascript\'%3E%3C/script%3E"));'."\n". 
							   t(5).'}'."\n".
							   t(5).'if (typeof slsBuild == "undefined"){'."\n".
							   		t(6).'var slsBuild = {<xsl:for-each select="//Statics/Sls/Configs/*"><xsl:variable name="firstPos" select="position()" /><xsl:variable name="nodeName" select="name()" /><xsl:if test="count(*[@js=\'true\'])!=0">\'<xsl:call-template name="protectString"><xsl:with-param name="str" select="$nodeName" /><xsl:with-param name="type">\'</xsl:with-param></xsl:call-template>\' :{<xsl:variable name="nbItems" select="count(*[@js=\'true\'])" /><xsl:for-each select="*[@js=\'true\']"><xsl:variable name="childName" select="name()" />\'<xsl:call-template name="protectString"><xsl:with-param name="str" select="$childName" /><xsl:with-param name="type">\'</xsl:with-param></xsl:call-template>\':\'<xsl:call-template name="protectString"><xsl:with-param name="str" select="." /><xsl:with-param name="type">\'</xsl:with-param></xsl:call-template>\'<xsl:if test="$nbItems != position()">,</xsl:if></xsl:for-each>},</xsl:if></xsl:for-each>\'langs\' : {<xsl:for-each select="//Statics/Sls/Langs/js/sentence">\'<xsl:call-template name="protectString"><xsl:with-param name="str" select="name" /><xsl:with-param name="type">\'</xsl:with-param></xsl:call-template>\' : \'<xsl:call-template name="protectString"><xsl:with-param name="str" select="value" /><xsl:with-param name="type">\'</xsl:with-param></xsl:call-template>\'<xsl:if test="position() != count(//Statics/Sls/Langs/js/sentence)">,</xsl:if></xsl:for-each>}};'."\n".
							   t(5).'}'."\n".
							   t(5).'if (typeof dp ==  "undefined"){'."\n".
					           		t(6).'document.write(unescape("%3Cscript src=\'<xsl:value-of select="$sls_url_js_core_statics" />highlight.js\'type=\'text/javascript\'%3E%3C/script%3E"));'."\n".
					           t(5).'}'."\n".
						   t(4).'</script>'."\n\n".	                
					       t(4).'<link rel="stylesheet" type="text/css" href="{concat($sls_url_css_core,\'ssBo.css\')}" />'."\n".
					       t(4).'<script type="text/javascript" src="{concat($sls_url_js_core_dyn, \'Selects.js\')}"></script>'."\n".
					       t(4).'<script type="text/javascript" src="{concat($sls_url_js_core_dyn, \'slsBo.js\')}"></script>'."\n".
						   t(4).'<link rel="stylesheet" type="text/css" href="{php:functionString(\'SLS_String::callCachingFile\', concat($sls_url_css_core, \'DevelopperToolbar.css\'))}" />'."\n".
			               t(4).'<script type="text/javascript" src="{php:functionString(\'SLS_String::callCachingFile\', concat($sls_url_js_core_dyn, \'DevelopperToolbar.js\'))}"></script>'."\n\n".	                
				       t(3).'</head>'."\n".
				       t(3).'<body>'."\n\n".
					       t(4).'<div id="bo_header">'."\n".
							   t(5).'<div class="left">'."\n".
							   		t(6).'<img src="{concat($sls_url_img_core,\'Logos/listing_logo.png\')}" alt="SillySmart BackOffice" title="SillySmart BackOffice" class="logo" />'."\n".
							   t(5).'</div>'."\n".
							   t(5).'<div class="right">'."\n".
								   t(6).'<a href="{//View/bo_actions/bo_action[label=\'Disconnection\']/url}" title="Logout" class="logout"><xsl:call-template name="displayLang"><xsl:with-param name="str" select="\'sls_bo_generic_logout\'" /><xsl:with-param name="escaping" select="\'yes\'" /></xsl:call-template></a>'."\n".
								   t(6).'<xsl:variable name="login"><xsl:choose><xsl:when test="//Statics/Sls/Session/params/param[name=\'SLS_BO_USER\']/value != \'\'"><xsl:value-of select="//Statics/Sls/Session/params/param[name=\'SLS_BO_USER\']/value" /></xsl:when><xsl:otherwise>SillySmart</xsl:otherwise></xsl:choose></xsl:variable>'."\n".
								   t(6).'<span class="logged"><xsl:call-template name="displayLang"><xsl:with-param name="str" select="\'sls_bo_generic_logged\'" /><xsl:with-param name="escaping" select="\'yes\'" /></xsl:call-template>&#160;<strong><xsl:value-of select="$login" /></strong> - </span>'."\n".
							   t(5).'</div>'."\n".
						   t(4).'</div>'."\n".
					       t(4).'<div id="bo_wrapper">'."\n".
							   t(5).'<div id="bo_float_wrapper">'."\n".
								   t(6).'<div id="content_wrapper">'."\n".
									   t(7).'<h1 class="main">'."\n".
							               t(8).'<xsl:call-template name="displayLang"><xsl:with-param name="str" select="\'sls_bo_generic_backoffice\'" /><xsl:with-param name="escaping" select="\'yes\'" /></xsl:call-template>&#160;'."\n".
							               t(8).'<span class="light"><xsl:value-of select="//Statics/Sls/Configs/site/projectName" /></span>'."\n".
							               t(8).'<span class="website">'."\n".
							               		t(9).'<span class="light"><xsl:value-of select="//Statics/Sls/Configs/site/projectName" /></span>&#160;'."\n".
							               		t(9).'<a href="{$sls_url_domain}"><xsl:call-template name="displayLang"><xsl:with-param name="str" select="\'sls_bo_generic_view_website\'" /><xsl:with-param name="escaping" select="\'yes\'" /></xsl:call-template></a>'."\n".
							               t(8).'</span>'."\n".	
						               t(7).'</h1>'."\n\n".
									   t(7).'<!-- Generic bodies loading -->'."\n".
									   t(7).'|||sls:loadActionFileBody|||'."\n".
									   t(7).'|||sls:loadCoreBody|||'."\n".
									   t(7).'<!-- /Generic bodies loading -->'."\n\n".
							       t(6).'</div>'."\n".
							   t(5).'</div>'."\n".
						   t(4).'</div>'."\n".
				       t(3).'</body>'."\n".
			       t(2).'</html>'."\n".
			   t(1).'</xsl:template>'."\n".
			   '</xsl:stylesheet>';
		file_put_contents($this->_generic->getPathConfig("viewsTemplates")."bo.xsl",$tpl1);
		
		$tpl2= '<!--'."\n".
			   '  - Global template for your application'."\n".
			   '  - Don\'t change anything between marked delimiter |||dtd:tagName|||'."\n".
			   '  - Beyond you can add additional headers or/and xhtml structure'."\n".
			   '-->'."\n".
			   '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" xmlns="http://www.w3.org/1999/xhtml">'."\n".
			   t(1).'<xsl:output method="xml" omit-xml-declaration="yes" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" indent="yes" encoding="|||sls:getCharset|||" />'."\n\n".
			   t(1).'<!-- Variable Builder -->'."\n".
			   t(1).'|||sls:buildUrlVars|||'."\n".
			   t(1).'<!-- /Variable Builder -->'."\n\n".			
			   t(1).'<!-- Generic include -->'."\n".
			   t(1).'|||sls:includeActionFileBody|||'."\n".
			   t(1).'|||sls:includeActionFileHeader|||'."\n".
			   t(1).'|||sls:includeStaticsFiles|||'."\n".
			   t(1).'<!-- /Generic include -->'."\n\n".			
			   t(1).'<xsl:template match="root">'."\n".
			       t(2).'<html xml:lang="|||sls:getLanguage|||" lang="|||sls:getLanguage|||">'."\n".
				       t(3).'<head>'."\n\n".			
					       t(4).'<!-- Generic headers loading -->'."\n".
					       t(4).'<xsl:call-template name="GenerateMetas" />'."\n".
					       t(4).'|||sls:loadCoreHeaders|||'."\n".
					       t(4).'|||sls:loadActionFileHeader|||'."\n".
					       t(4).'<!-- /Generic headers loading -->'."\n\n".			                
					       t(4).'<link rel="stylesheet" type="text/css" href="{concat($sls_url_css_core,\'ssBoLogin.css\')}" />'."\n".
					       t(4).'<script type="text/javascript" src="{concat($sls_url_js_core_statics, \'SLS_Statics_compressed.js\')}"></script>'."\n".
					       t(4).'<script type="text/javascript" src="{concat($sls_url_js_core_dyn, \'slsBo.js\')}"></script>'."\n\n".			                
				       t(3).'</head>'."\n".
				       t(3).'<body>'."\n\n".		       
						   t(4).'<!-- Generic bodies loading -->'."\n".
						   t(4).'|||sls:loadActionFileBody|||'."\n".
						   t(4).'|||sls:loadCoreBody|||'."\n".
						   t(4).'<!-- /Generic bodies loading -->'."\n\n".
				       t(3).'</body>'."\n".
			       t(2).'</html>'."\n".
			   t(1).'</xsl:template>'."\n".
			   '</xsl:stylesheet>';
		file_put_contents($this->_generic->getPathConfig("viewsTemplates")."bo_login.xsl",$tpl2);
		
		$tpl3= '<!--'."\n".
			   '  - Global template for your application'."\n".
			   '  - Don\'t change anything between marked delimiter |||dtd:tagName|||'."\n".
			   '  - Beyond you can add additional headers or/and xhtml structure'."\n".
			   '-->'."\n".
			   '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" xmlns="http://www.w3.org/1999/xhtml">'."\n".
			   t(1).'<xsl:output method="xml" omit-xml-declaration="yes" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" indent="yes" encoding="|||sls:getCharset|||" />'."\n\n".
			   t(1).'<!-- Variable Builder -->'."\n".
			   t(1).'|||sls:buildUrlVars|||'."\n".
			   t(1).'<!-- /Variable Builder -->'."\n\n".			
			   t(1).'<!-- Generic include -->'."\n".
			   t(1).'|||sls:includeActionFileBody|||'."\n".
			   t(1).'|||sls:includeActionFileHeader|||'."\n".
			   t(1).'|||sls:includeStaticsFiles|||'."\n".
			   t(1).'<!-- /Generic include -->'."\n\n".			
			   t(1).'<xsl:template match="root">'."\n".
			       t(2).'<html xml:lang="|||sls:getLanguage|||" lang="|||sls:getLanguage|||">'."\n".
				       t(3).'<head>'."\n\n".
					       t(4).'<!-- Generic headers loading -->'."\n".
					       t(4).'<xsl:call-template name="GenerateMetas" />'."\n".			   
					       t(4).'|||sls:loadActionFileHeader|||'."\n".
					       t(4).'<!-- /Generic headers loading -->'."\n\n".
						   t(4).'<script type="text/javascript">'."\n".
							   t(5).'if (typeof MooTools == "undefined"){'."\n".
							   		t(6).'document.write(unescape("%3Cscript src=\'<xsl:value-of select="$sls_url_js_core_statics" />SLS_Statics_compressed.js\'type=\'text/javascript\'%3E%3C/script%3E"));'."\n". 
							   t(5).'}'."\n".
							   t(5).'if (typeof slsBuild == "undefined"){'."\n".
							   		t(6).'var slsBuild = {<xsl:for-each select="//Statics/Sls/Configs/*"><xsl:variable name="firstPos" select="position()" /><xsl:variable name="nodeName" select="name()" /><xsl:if test="count(*[@js=\'true\'])!=0">\'<xsl:call-template name="protectString"><xsl:with-param name="str" select="$nodeName" /><xsl:with-param name="type">\'</xsl:with-param></xsl:call-template>\' :{<xsl:variable name="nbItems" select="count(*[@js=\'true\'])" /><xsl:for-each select="*[@js=\'true\']"><xsl:variable name="childName" select="name()" />\'<xsl:call-template name="protectString"><xsl:with-param name="str" select="$childName" /><xsl:with-param name="type">\'</xsl:with-param></xsl:call-template>\':\'<xsl:call-template name="protectString"><xsl:with-param name="str" select="." /><xsl:with-param name="type">\'</xsl:with-param></xsl:call-template>\'<xsl:if test="$nbItems != position()">,</xsl:if></xsl:for-each>},</xsl:if></xsl:for-each>\'langs\' : {<xsl:for-each select="//Statics/Sls/Langs/js/sentence">\'<xsl:call-template name="protectString"><xsl:with-param name="str" select="name" /><xsl:with-param name="type">\'</xsl:with-param></xsl:call-template>\' : \'<xsl:call-template name="protectString"><xsl:with-param name="str" select="value" /><xsl:with-param name="type">\'</xsl:with-param></xsl:call-template>\'<xsl:if test="position() != count(//Statics/Sls/Langs/js/sentence)">,</xsl:if></xsl:for-each>}};'."\n".
							   t(5).'}'."\n".
							   t(5).'if (typeof dp ==  "undefined"){'."\n".
					           		t(6).'document.write(unescape("%3Cscript src=\'<xsl:value-of select="$sls_url_js_core_statics" />highlight.js\'type=\'text/javascript\'%3E%3C/script%3E"));'."\n".
					           t(5).'}'."\n".
						   t(4).'</script>'."\n\n".	                
					       t(4).'<link rel="stylesheet" type="text/css" href="{concat($sls_url_css_core,\'ssBo.css\')}" />'."\n".
					       t(4).'<script type="text/javascript" src="{concat($sls_url_js_core_dyn, \'Selects.js\')}"></script>'."\n".
					       t(4).'<script type="text/javascript" src="{concat($sls_url_js_core_dyn, \'slsBo.js\')}"></script>'."\n\n".						   	                
				       t(3).'</head>'."\n".
				       t(3).'<body>'."\n\n".					       
					       t(4).'<div id="bo_wrapper" class="light_override">'."\n".
							   t(5).'<div id="bo_float_wrapper">'."\n".
								   t(6).'<div id="content_wrapper">'."\n\n".									   
									   t(7).'<!-- Generic bodies loading -->'."\n".
									   t(7).'|||sls:loadActionFileBody|||'."\n".
									   t(7).'|||sls:loadCoreBody|||'."\n".
									   t(7).'<!-- /Generic bodies loading -->'."\n\n".
							       t(6).'</div>'."\n".
							   t(5).'</div>'."\n".
						   t(4).'</div>'."\n".
				       t(3).'</body>'."\n".
			       t(2).'</html>'."\n".
			   t(1).'</xsl:template>'."\n".
			   '</xsl:stylesheet>';
		file_put_contents($this->_generic->getPathConfig("viewsTemplates")."bo_light.xsl",$tpl3);
	}
	
	/**
	 * Create bo action connection
	 *
	 * @param string $controllerBo generic controller name (Bo)
	 */
	protected function createActionBoConnection($controllerBo="")
	{
		$langs = $this->_generic->getObjectLang()->getSiteLangs();		
		$params = array(0 => array("key" 	=> "reload",
				  				   "value" 	=> "true"),
				  		1 => array("key" 	=> "Controller",
				  				   "value" 	=> $controllerBo),
					 	2 => array("key" 	=> "actionName",
				  				   "value" 	=> "Connection"),
				  		3 => array("key"	=> "token",
				  				   "value"	=> sha1(substr($this->_generic->getSiteConfig("privateKey"), 0, 3).substr($this->_generic->getSiteConfig("privateKey"), strlen($this->_generic->getSiteConfig("privateKey"))-3))),
				  		4 => array("key"	=> "indexes",
				  				   "value"	=> "noindex,nofollow"),
				  		5 => array("key"	=> "default",
				  				   "value"  => "1"),
				  		6 => array("key" 	=> "template",
				  				   "value" 	=> "bo_login")				  			
					    );
		foreach($langs as $lang)
		{
			$tmpParam = array("key" 	=> $lang."-action",
							  "value" 	=> "Connection");
			$tmpTitle = array("key" 	=> $lang."-title",
							  "value" 	=> "Connection");
			array_push($params,$tmpParam);
			array_push($params,$tmpTitle);
		}
		file_get_contents($this->_generic->getFullPath("SLS_Bo",
													  "AddAction",
													  $params,
													  true));
		
		$source = file_get_contents($this->_generic->getPathConfig("actionsControllers").$controllerBo."/Connection.controller.php");
		
		$action = t(2).'$xml = $this->getXML();'."\n".
				  t(2).'$boActions = SLS_BoRights::getDistinctActions();'."\n".
        		  t(2).'$xml->startTag("bo_actions");'."\n".
        		  t(2).'for($i=0 ; $i<$count=count($boActions) ; $i++)'."\n".
        		  t(2).'{'."\n".
	        		  t(3).'$xml->startTag("bo_action");'."\n".
	        		  t(3).'foreach($boActions[$i] as $key => $value)'."\n".
	        		  		t(4).'$xml->addFullTag($key,$value,true);'."\n".
	        		  t(3).'$xml->endTag("bo_action");'."\n".
        		  t(2).'}'."\n".
        		  t(2).'$xml->endTag("bo_actions");'."\n".
				  t(2).'if ($this->_http->getParam("reload") == "true")'."\n".
				  t(2).'{'."\n".
					  t(3).'$login 	 = $this->_http->getParam("login");'."\n".
					  t(3).'$password = $this->_http->getParam("password");'."\n".
					  t(3).'if (!SLS_BoRights::connect($login,$password))'."\n".
					  t(3).'{'."\n".
					  		t(4).'$xml->startTag("errors");'."\n".
					  		t(4).'$xml->addFullTag("error","Access denied",true);'."\n".
					  		t(4).'$xml->endTag("errors");'."\n".
					  t(3).'}'."\n".
				  t(2).'}'."\n".
				  t(2).'if (SLS_BoRights::isLogged())'."\n".
				  t(2).'{'."\n".
					  t(3).'$xml->addFullTag("isLogged","true",true);'."\n".
					  t(3).'if (count($boActions) > 1)'."\n".
					  		t(4).'$this->_generic->redirect($boActions[0]["url"]);'."\n".
				  t(2).'}'.
				  t(2).'$this->saveXML($xml);'."\n";
		$source = substr($source,0,strpos($source,"action()")+8)."\n".
				  t(1).'{'."\n".
				  $action.
				  t(1).'}'."\n".
				  '}'."\n".
				  '?>';
		
		file_put_contents($this->_generic->getPathConfig("actionsControllers").$controllerBo."/Connection.controller.php",$source);
				
		$sourceXsl = '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" xmlns="http://www.w3.org/1999/xhtml">'."\n".
					 t(1).'<xsl:template name="Connection">'."\n".
						 t(2).'<script type="text/javascript">'."\n".
						 	t(3).'page = \'login\';'."\n".
					     t(2).'</script>'."\n".
			             t(2).'<div id="login_box_wrapper">'."\n".
							 t(3).'<img src="{concat($sls_url_img_core,\'Logos/login_logo.png\')}" alt="SillySmart BackOffice" title="SillySmart BackOffice" class="logo"/>'."\n".
							 t(3).'<fieldset class="login_form">'."\n".
								 t(4).'<div class="top"></div>'."\n".
								 t(4).'<div class="content">'."\n".
									 t(5).'<xsl:if test="count(//View/errors/error) &gt; 0">'."\n".
										 t(6).'<ul class="error">'."\n".
											 t(7).'<xsl:for-each select="//View/errors/error">'."\n".
											 	t(8).'<li><xsl:value-of select="." /></li>'."\n".
											 t(7).'</xsl:for-each>'."\n".
										 t(6).'</ul>'."\n".
									 t(5).'</xsl:if>'."\n".
									 t(5).'<form action="" method="post">'."\n".
										 t(6).'<input type="hidden" name="reload" value="true" />'."\n".
										 t(6).'<div class="row">'."\n".
											 t(7).'<label for="username"><xsl:call-template name="displayLang"><xsl:with-param name="str" select="\'sls_bo_login_user\'" /><xsl:with-param name="escaping" select="\'yes\'" /></xsl:call-template></label>'."\n".
											 t(7).'<div class="login_input">'."\n".
											 	t(8).'<input type="text" name="login" id="username" />'."\n".
											 t(7).'</div>'."\n".
										 t(6).'</div>'."\n".
										 t(6).'<div class="row">'."\n".
											 t(7).'<label for="pass"><xsl:call-template name="displayLang"><xsl:with-param name="str" select="\'sls_bo_login_password\'" /><xsl:with-param name="escaping" select="\'yes\'" /></xsl:call-template></label>'."\n".
											 t(7).'<div class="login_input">'."\n".
											 	t(8).'<input type="password" name="password" id="pass" />'."\n".
											 t(7).'</div>'."\n".
										 t(6).'</div>'."\n".
										 t(6).'<div class="row">'."\n".
											 t(7).'<div class="login_submit">'."\n".
												 t(8).'<div class="left"></div>'."\n".
												 t(8).'<div class="middle">'."\n".
													 t(9).'<input type="submit">'."\n".
													 	t(10).'<xsl:attribute name="value"><xsl:call-template name="displayLang"><xsl:with-param name="str" select="\'sls_bo_login_submit\'" /><xsl:with-param name="escaping" select="\'yes\'" /></xsl:call-template></xsl:attribute>'."\n".
													 t(9).'</input>'."\n".
												 t(8).'</div>'."\n".
												 t(8).'<div class="right"></div>'."\n".
											 t(7).'</div>'."\n".
										 t(6).'</div>'."\n".
									 t(5).'</form>'."\n".
								 t(4).'</div>'."\n".
								 t(4).'<div class="foot"></div>'."\n".
							 t(3).'</fieldset>'."\n".
					     t(2).'</div>'."\n".
					 t(1).'</xsl:template>'."\n".
					 '</xsl:stylesheet>';
		file_put_contents($this->_generic->getPathConfig("viewsBody").$controllerBo."/Connection.xsl",$sourceXsl);
	}
	
	/**
	 * Create bo action renew pwd
	 *
	 * @param string $controllerBo generic controller name (Bo)
	 */
	protected function createActionBoRenewPwd($controllerBo="")
	{
		$langs = $this->_generic->getObjectLang()->getSiteLangs();		
		$params = array(0 => array("key" 	=> "reload",
				  				   "value" 	=> "true"),
				  		1 => array("key" 	=> "Controller",
				  				   "value" 	=> $controllerBo),
					 	2 => array("key" 	=> "actionName",
				  				   "value" 	=> "RenewPwd"),
				  		3 => array("key"	=> "token",
				  				   "value"	=> sha1(substr($this->_generic->getSiteConfig("privateKey"), 0, 3).substr($this->_generic->getSiteConfig("privateKey"), strlen($this->_generic->getSiteConfig("privateKey"))-3))),
				  		4 => array("key"	=> "indexes",
				  				   "value"	=> "noindex,nofollow"),				  		
				  		5 => array("key" 	=> "template",
				  				   "value" 	=> "bo_login")
					    );
		foreach($langs as $lang)
		{
			$tmpParam = array("key" 	=> $lang."-action",
							  "value" 	=> "RenewPwd");
			$tmpTitle = array("key" 	=> $lang."-title",
							  "value" 	=> "RenewPwd");
			array_push($params,$tmpParam);
			array_push($params,$tmpTitle);
		}
		file_get_contents($this->_generic->getFullPath("SLS_Bo",
													  "AddAction",
													  $params,
													  true));
		
		$source = file_get_contents($this->_generic->getPathConfig("actionsControllers").$controllerBo."/RenewPwd.controller.php");
		
		$action = 	t(2).'$xml = $this->getXML();'."\n".
					t(2).'$xmlRights = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/rights.xml"));'."\n".
					t(2).'$errors = array();'."\n\n".		
					t(2).'$login = $this->_http->getParam("Login");'."\n\n".		
					t(2).'if ($this->_http->getParam("reload") == "true")'."\n".
					t(2).'{'."\n".
						t(3).'$attributes = array_shift($xmlRights->getTagsAttributes("//sls_configs/entry[@login=\'".($login)."\']",array("password","complexity_pwd","min_chars_pwd","renew_pwd_nb","password_old","reset_pwd")));'."\n".
						t(3).'$complexity = explode("|",$attributes["attributes"][1]["value"]);'."\n".
						t(3).'$old_passwords = explode("|",$attributes["attributes"][4]["value"]);'."\n\n".			
						t(3).'$current_password 	= SLS_String::trimSlashesFromString($this->_http->getParam("current_password"));'."\n".
						t(3).'$new_password 		= SLS_String::trimSlashesFromString(trim($this->_http->getParam("new_password")));'."\n".
						t(3).'$new_password2 		= SLS_String::trimSlashesFromString(trim($this->_http->getParam("new_password2")));'."\n\n".			
						t(3).'if (sha1($current_password) != $attributes["attributes"][0]["value"])'."\n".
							t(4).'array_push($errors,$GLOBALS[$GLOBALS[\'PROJECT_NAME\']][\'JS\'][\'SLS_BO_RENEW_ERROR_CURRENT_PASSWORD\']);'."\n".			
						t(3).'else'."\n".
						t(3).'{'."\n".
							t(4).'if (empty($new_password))'."\n".
								t(5).'array_push($errors, $GLOBALS[$GLOBALS[\'PROJECT_NAME\']][\'JS\'][\'SLS_BO_RENEW_ERROR_NEW_PASSWORD_EMPTY\']);'."\n".
							t(4).'else if ($new_password != $new_password2)'."\n".
								t(5).'array_push($errors, $GLOBALS[$GLOBALS[\'PROJECT_NAME\']][\'JS\'][\'SLS_BO_RENEW_ERROR_NEW_PASSWORD_BOTH\']);'."\n".
							t(4).'else if ($current_password == $new_password)'."\n".
								t(5).'array_push($errors, $GLOBALS[$GLOBALS[\'PROJECT_NAME\']][\'JS\'][\'SLS_BO_RENEW_ERROR_NEW_PASSWORD_SAME_CURRENT\']);'."\n".
							t(4).'else'."\n".
							t(4).'{'."\n".
								t(5).'if (strlen($new_password) < $attributes["attributes"][2]["value"])'."\n".
									t(6).'array_push($errors, sprintf($GLOBALS[$GLOBALS[\'PROJECT_NAME\']][\'JS\'][\'SLS_BO_RENEW_ERROR_NEW_PASSWORD_MIN_CHARACTERS\'], $attributes["attributes"][2]["value"]));'."\n".
								t(5).'if (in_array("lc",$complexity) && preg_match(\'`[[:lower:]]`\', $new_password) === 0)'."\n".
									t(6).'array_push($errors, $GLOBALS[$GLOBALS[\'PROJECT_NAME\']][\'JS\'][\'SLS_BO_RENEW_ERROR_NEW_PASSWORD_LC\']);'."\n".
								t(5).'if (in_array("uc",$complexity) && preg_match(\'`[[:upper:]]`\', $new_password) === 0)'."\n".
									t(6).'array_push($errors, $GLOBALS[$GLOBALS[\'PROJECT_NAME\']][\'JS\'][\'SLS_BO_RENEW_ERROR_NEW_PASSWORD_UC\']);'."\n".
								t(5).'if (in_array("digit",$complexity) && preg_match(\'`[[:digit:]]`\', $new_password) === 0)'."\n".
									t(6).'array_push($errors, $GLOBALS[$GLOBALS[\'PROJECT_NAME\']][\'JS\'][\'SLS_BO_RENEW_ERROR_NEW_PASSWORD_DIGIT\']);'."\n".
								t(5).'if (in_array("special_char",$complexity) && preg_match(\'`[^a-zA-Z0-9]`\', $new_password) === 0)'."\n".
									t(6).'array_push($errors, $GLOBALS[$GLOBALS[\'PROJECT_NAME\']][\'JS\'][\'SLS_BO_RENEW_ERROR_NEW_PASSWORD_SPECIAL_CHAR\']);'."\n".
								t(5).'if (in_array(sha1($new_password),$old_passwords))'."\n".
									t(6).'array_push($errors, sprintf($GLOBALS[$GLOBALS[\'PROJECT_NAME\']][\'JS\'][\'SLS_BO_RENEW_ERROR_NEW_PASSWORD_SAME_OLDS\'], $attributes["attributes"][3]["value"]));'."\n".
							t(4).'}'."\n".
						t(3).'}'."\n\n".			
						t(3).'if (empty($errors))'."\n".
						t(3).'{'."\n".
							t(4).'if ($attributes["attributes"][5]["value"] == "true")'."\n".				
								t(5).'$xmlRights->setTagAttributes("//sls_configs/entry[@login=\'".$login."\']",array("reset_pwd" => ""));'."\n".
							t(4).'$xmlRights->setTagAttributes("//sls_configs/entry[@login=\'".$login."\']",array("password" => sha1($new_password)));'."\n".
							t(4).'$xmlRights->setTagAttributes("//sls_configs/entry[@login=\'".$login."\']",array("last_renew_pwd" => date("Y-m-d")));'."\n".
							t(4).'if (count($old_passwords) < $attributes["attributes"][3]["value"])'."\n".
							t(4).'{'."\n".
								t(5).'array_unshift($old_passwords,sha1($current_password));'."\n".
								t(5).'$xmlRights->setTagAttributes("//sls_configs/entry[@login=\'".$login."\']",array("password_old" => implode("|",$old_passwords)));'."\n".
							t(4).'}'."\n".
							t(4).'else'."\n".
							t(4).'{'."\n".
								t(5).'array_pop($old_passwords);'."\n".
								t(5).'array_unshift($old_passwords,sha1($current_password));'."\n".
								t(5).'$xmlRights->setTagAttributes("//sls_configs/entry[@login=\'".$login."\']",array("password_old" => implode("|",$old_passwords)));'."\n".
							t(4).'}'."\n".
							t(4).'$xmlRights->saveXML($this->_generic->getPathConfig("configSls")."/rights.xml",$xmlRights->getXML());'."\n\n".				
							t(4).'SLS_BoRights::connect($login,$new_password);'."\n\n".				
							t(4).'$this->_generic->forward(array_shift($this->_generic->getControllersXML()->getTags("//controllers/controller[@isBo=\'true\']/@name")),"Connection");'."\n".
						t(3).'}'."\n".
						t(3).'else'."\n".
						t(3).'{'."\n".
							t(4).'$xml->startTag("errors");'."\n".
							t(4).'foreach($errors as $error)'."\n".
								t(5).'$xml->addFullTag("error",$error,true);'."\n".
							t(4).'$xml->endTag("errors");'."\n".
						t(3).'}'."\n".
					t(2).'}'."\n\n".		
					t(2).'$attributes = array_shift($xmlRights->getTagsAttributes("//sls_configs/entry[@login=\'".($login)."\']",array("complexity_pwd","min_chars_pwd","renew_pwd_nb")));'."\n\n".		
					t(2).'$complexity_collection = explode("|",$attributes["attributes"][0]["value"]);'."\n".
					t(2).'$complexity_litteral = "";'."\n".
					t(2).'for($i=0 ; $i<$count=count($complexity_collection) ; $i++)'."\n".
						t(3).'$complexity_litteral .= $GLOBALS[$GLOBALS[\'PROJECT_NAME\']][\'JS\'][\'SLS_BO_RENEW_PASSWORD_COMPLEXITY_CHARS_\'.strtoupper($complexity_collection[$i])].(($i<($count-1)) ? ", " : "");'."\n".
					t(2).'$xml->startTag("infos");'."\n".
						t(3).'$xml->addFullTag("complexity_pwd",str_replace("|",", ",$attributes["attributes"][0]["value"]),true);'."\n".
						t(3).'$xml->addFullTag("complexity_pwd_litteral",$complexity_litteral,true);'."\n".
						t(3).'$xml->addFullTag("min_chars_pwd",$attributes["attributes"][1]["value"],true);'."\n".
						t(3).'$xml->addFullTag("renew_pwd_nb",$attributes["attributes"][2]["value"],true);'."\n".
					t(2).'$xml->endTag("infos");'."\n\n".		
					t(2).'$this->saveXML($xml);'."\n";
		
		$source = substr($source,0,strpos($source,"action()")+8)."\n".
				  t(1).'{'."\n".
				  $action.
				  t(1).'}'."\n".
				  '}'."\n".
				  '?>';
		
		file_put_contents($this->_generic->getPathConfig("actionsControllers").$controllerBo."/RenewPwd.controller.php",$source);
				
		$sourceXsl = '<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl" xmlns="http://www.w3.org/1999/xhtml">'."\n".
					 t(1).'<xsl:template name="RenewPwd">'."\n".
						 t(2).'<script type="text/javascript">'."\n".
						 	t(3).'page = \'login\';'."\n".
					     t(2).'</script>'."\n".
			             t(2).'<div id="login_box_wrapper">'."\n".
							 t(3).'<img src="{concat($sls_url_img_core,\'Logos/login_logo.png\')}" alt="SillySmart BackOffice" title="SillySmart BackOffice" class="logo"/>'."\n".
							 t(3).'<fieldset class="login_form">'."\n".
								 t(4).'<div class="top"></div>'."\n".
								 t(4).'<div class="content">'."\n".
									 t(5).'<xsl:if test="//View/infos/complexity_pwd != \'\' or //View/infos/min_chars_pwd != \'\' or //View/infos/renew_pwd_nb != \'\'">'."\n".
										t(6).'<ul class="warning">'."\n".
											t(7).'<xsl:if test="//View/infos/complexity_pwd != \'\' or //View/infos/min_chars_pwd != \'\'">'."\n".
												t(8).'<u><xsl:call-template name="displayLang"><xsl:with-param name="str" select="\'sls_bo_renew_password_must_contain\'" /><xsl:with-param name="escaping" select="\'yes\'" /></xsl:call-template></u><br />'."\n".
												t(8).'<xsl:if test="//View/infos/min_chars_pwd != \'\'">'."\n".
													t(9).'- <xsl:value-of select="//View/infos/min_chars_pwd" />&#160;<xsl:call-template name="displayLang"><xsl:with-param name="str" select="\'sls_bo_renew_password_min_chars\'" /><xsl:with-param name="escaping" select="\'yes\'" /></xsl:call-template><br />'."\n".
												t(8).'</xsl:if>'."\n".
												t(8).'<xsl:if test="//View/infos/complexity_pwd != \'\'">'."\n".
													t(9).'- <xsl:call-template name="displayLang"><xsl:with-param name="str" select="\'sls_bo_renew_password_complexity_chars\'" /><xsl:with-param name="escaping" select="\'yes\'" /></xsl:call-template>&#160;<xsl:value-of select="//View/infos/complexity_pwd_litteral" /><br />'."\n".
												t(8).'</xsl:if>'."\n".
											t(7).'</xsl:if>'."\n".
											t(7).'<xsl:if test="//View/infos/renew_pwd_nb != \'\'">'."\n".
												t(8).'<em>'."\n".
													t(9).'<xsl:variable name="sentence"><xsl:call-template name="displayLang"><xsl:with-param name="str" select="\'sls_bo_renew_password_note\'" /><xsl:with-param name="escaping" select="\'yes\'" /></xsl:call-template></xsl:variable>'."\n".
													t(9).'<xsl:value-of select="php:functionString(\'SLS_String::formatXslString\',$sentence,//View/infos/renew_pwd_nb)" disable-output-escaping="yes" />'."\n".
												t(8).'</em>'."\n".
											t(7).'</xsl:if>'."\n".
										t(6).'</ul>'."\n".
									t(5).'</xsl:if>'."\n".
									t(5).'<xsl:if test="count(//View/errors/error) &gt; 0">'."\n".
										t(6).'<ul class="error">'."\n".
											t(7).'<xsl:for-each select="//View/errors/error">'."\n".
												t(8).'<li><xsl:value-of select="." /></li>'."\n".
											t(7).'</xsl:for-each>'."\n".
										t(6).'</ul>'."\n".
									t(5).'</xsl:if>'."\n".
									t(5).'<form action="" method="post">'."\n".
										t(6).'<input type="hidden" name="reload" value="true" />'."\n".
										t(6).'<div class="row">'."\n".
											t(7).'<label for="current_password"><xsl:call-template name="displayLang"><xsl:with-param name="str" select="\'sls_bo_renew_current_password\'" /><xsl:with-param name="escaping" select="\'yes\'" /></xsl:call-template></label>'."\n".
											t(7).'<div class="login_input">'."\n".
												t(8).'<input type="password" name="current_password" id="current_password" />'."\n".
											t(7).'</div>'."\n".
										t(6).'</div>'."\n".
										t(6).'<div class="row">'."\n".
											t(7).'<label for="new_password"><xsl:call-template name="displayLang"><xsl:with-param name="str" select="\'sls_bo_renew_new_password\'" /><xsl:with-param name="escaping" select="\'yes\'" /></xsl:call-template></label>'."\n".
											t(7).'<div class="login_input">'."\n".
												t(8).'<input type="password" name="new_password" id="new_password" />'."\n".
											t(7).'</div>'."\n".
										t(6).'</div>'."\n".
										t(6).'<div class="row">'."\n".
											t(7).'<label for="new_password2"><xsl:call-template name="displayLang"><xsl:with-param name="str" select="\'sls_bo_renew_confirm_password\'" /><xsl:with-param name="escaping" select="\'yes\'" /></xsl:call-template></label>'."\n".
											t(7).'<div class="login_input">'."\n".
												t(8).'<input type="password" name="new_password2" id="new_password2" />'."\n".
											t(7).'</div>'."\n".
										t(6).'</div>'."\n".
										t(6).'<div class="row">'."\n".
											t(7).'<div class="login_submit">'."\n".
												t(8).'<div class="left"></div>'."\n".
												t(8).'<div class="middle">'."\n".
													t(9).'<input type="submit">'."\n".
														t(10).'<xsl:attribute name="value"><xsl:call-template name="displayLang"><xsl:with-param name="str" select="\'sls_bo_renew_update_password\'" /><xsl:with-param name="escaping" select="\'yes\'" /></xsl:call-template></xsl:attribute>'."\n".
													t(9).'</input>'."\n".
												t(8).'</div>'."\n".
												t(8).'<div class="right"></div>'."\n".
											t(7).'</div>'."\n".
										t(6).'</div>'."\n".
									t(5).'</form>'."\n".
								 t(4).'</div>'."\n".
								 t(4).'<div class="foot"></div>'."\n".
							 t(3).'</fieldset>'."\n".
					     t(2).'</div>'."\n".
					 t(1).'</xsl:template>'."\n".
					 '</xsl:stylesheet>';
		file_put_contents($this->_generic->getPathConfig("viewsBody").$controllerBo."/RenewPwd.xsl",$sourceXsl);
	}
	
	/**
	 * Create bo action export
	 *
	 * @param string $controllerBo generic controller name (Bo)
	 */
	protected function createActionBoExport($controllerBo="")
	{
		$langs = $this->_generic->getObjectLang()->getSiteLangs();		
		$params = array(0 => array("key" 	=> "reload",
				  				   "value" 	=> "true"),
				  		1 => array("key" 	=> "Controller",
				  				   "value" 	=> $controllerBo),
					 	2 => array("key" 	=> "actionName",
				  				   "value" 	=> "Export"),
				  		3 => array("key"	=> "token",
				  				   "value"	=> sha1(substr($this->_generic->getSiteConfig("privateKey"), 0, 3).substr($this->_generic->getSiteConfig("privateKey"), strlen($this->_generic->getSiteConfig("privateKey"))-3)),
				  		4 => array("key"	=> "indexes",
				  				   "value"	=> "noindex,nofollow")
				  			)
					    );
		foreach($langs as $lang)
		{
			$tmpParam = array("key" 	=> $lang."-action",
							  "value" 	=> "Export");
			$tmpTitle = array("key" 	=> $lang."-title",
							  "value" 	=> "Export");
			array_push($params,$tmpParam);
			array_push($params,$tmpTitle);
		}
		file_get_contents($this->_generic->getFullPath("SLS_Bo",
													  "AddAction",
													  $params,
													  true));
		
		$source = file_get_contents($this->_generic->getPathConfig("actionsControllers").$controllerBo."/Export.controller.php");
		
		$action =   t(2).'$http = $this->_generic->getObjectHttpRequest();'."\n".
			        t(2).'$columns = array();'."\n".
			        t(2).'$clause = array();'."\n".
			        t(2).'$join = array();'."\n".
			        t(2).'// Model + Db alias + Join'."\n".
			        t(2).'$model = $http->getParam("Export_Model");'."\n".
			        t(2).'$db = $http->getParam("Export_Db");'."\n".
			        t(2).'$nJoin = $http->getParam("Export_Join");'."\n".
			        t(2).'if (!empty($nJoin))'."\n".
			        	t(3).'$join = explode(",",$nJoin);'."\n".
			        t(2).'$nbColumns = count(SLS_Sql::getInstance()->getColumnsName($model));'."\n".
			        t(2).'// Columns'."\n".
			        t(2).'foreach($http->getParams() as $key => $value)'."\n".
			        	t(3).'if (SLS_String::startsWith($key,"Export_Column_"))'."\n".
			        		t(4).'array_push($columns,$value);'."\n".
			        t(2).'// Pagination + Order'."\n".
			        t(2).'$column = ($http->getParam("column") == "|sls_empty|") ? "" : $http->getParam("column");'."\n".
			        t(2).'$order = ($http->getParam("order") == "|sls_empty|") ? "" : $http->getParam("order");'."\n".
			        t(2).'// Filters'."\n".
			        t(2).'for($i=0 ; $i<$nbColumns ; $i++)'."\n".
			        t(2).'{'."\n".
			        	t(3).'if ($http->getParam("filter_exact_".($i+1)) == "null" ||'."\n". 
					        t(4).'$http->getParam("filter_exact_".($i+1)) == "notnull" ||'."\n".
					        t(4).'$http->getParam("filter_value_".($i+1)) != "")'."\n".
			        	t(3).'{'."\n".
					        t(4).'if ($http->getParam("filter_value_".($i+1)) != "|sls_empty|")'."\n".
					        t(4).'{'."\n".
			        			t(5).'$arrayTmp = array("column" => $http->getParam("filter_name_".($i+1)),'."\n".
											        t(9).'"value"  => ($http->getParam("filter_exact_".($i+1)) == "in") ? explode(",",$http->getParam("filter_value_".($i+1))) : $http->getParam("filter_value_".($i+1)),'."\n".
											        t(9).'"mode"   => $http->getParam("filter_exact_".($i+1)));'."\n".
											        t(9).'array_push($clause,$arrayTmp);'."\n".
			        		t(4).'}'."\n".
			        	t(3).'}'."\n".
			        t(2).'}'."\n".
			        t(2).'if ($this->_generic->useModel($model,$db))'."\n".
			        t(2).'{'."\n".
			        	t(3).'if (!empty($column) && !empty($order))'."\n".
			        		t(4).'$order = array(0=>array("column"=>$column,"order"=>$order));'."\n".
				        t(3).'else'."\n".
				        	t(4).'$order = array();'."\n".
				        t(3).'$className = ucfirst($db)."_".SLS_String::tableToClass($model);'."\n".
				        t(3).'$object = new $className();'."\n".
				        t(3).'$entities = $object->searchModels("",$join,$clause,array(),$order);'."\n".
				        t(3).'$type = $http->getParam("Export_Type");'."\n".
				        t(3).'$xmlType = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/types.xml"));'."\n".
				        t(3).'$xmlFilter = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/filters.xml"));'."\n".
				        t(3).'$types = array();'."\n".
				        t(3).'switch($type)'."\n".
				        t(3).'{'."\n".
					        t(4).'case "excel":'."\n".
						        t(5).'$title = $object->getTableComment($model,$db)." Listing";'."\n".
						        t(5).'header("Content-Type: application/vnd.ms-excel");'."\n".
						        t(5).'header("Content-Disposition: attachment; filename=\"".$title."\".xls");'."\n".
						        t(5).'$src = \'<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body style="font-family:\\\'Franklin Gothic Book\\\', Verdana, Helvetica, Arial;"><table>\';'."\n".
						        t(5).'$src .= \'<tr>\';'."\n".
						        t(5).'$tables = array($object->getTable());'."\n".
						        t(5).'foreach($join as $cur_join)'."\n".
						        	t(6).'array_push($tables,(is_array($cur_join)) ? $cur_join["table"] : $cur_join);'."\n".
						        t(5).'for($k=0 ; $k<$count3=count($columns) ; $k++)'."\n".
						        t(5).'{'."\n".
							        t(6).'$description = $object->getColumnComment($columns[$k],$model,$db);'."\n".
							        t(6).'if ($description == $columns[$k] && !empty($join))'."\n".
							        	t(7).'$description = $object->getColumnComment($columns[$k],$join[0],$db);'."\n".
							        t(6).'$src .= \'<td style="text-align:center;background-color:#CAC3ED;color:#100F16;border:1px solid gray;font-weight:bold;font-size:14px;">\'.$description.\'</td>\';'."\n\n".									
									t(6).'foreach($tables as $table)'."\n".
									t(6).'{'."\n".
										t(7).'// Search possible types'."\n".
										t(7).'$result = array_shift($xmlType->getTagsAttribute("//sls_configs/entry[@table=\'".$object->getDatabase()."_".$table."\' and @column=\'".$columns[$k]."\' and (@type = \'file_img\' or @type = \'file_all\' or @type = \'email\' or @type = \'url\')]","type"));'."\n".
										t(7).'if (!empty($result["attribute"]))'."\n".
										t(7).'{'."\n".
											t(8).'$types[$k] = $result["attribute"];'."\n".
											t(8).'break;'."\n".
										t(7).'}'."\n".
										t(7).'else'."\n".
											t(8).'$types[$k] = "";'."\n\n".										    
										t(7).'// Search possible filters'."\n".
										t(7).'$result = array_shift($xmlFilter->getTagsAttribute("//sls_configs/entry[@table=\'".$object->getDatabase()."_".$table."\' and @column=\'".$columns[$k]."\' and @filter=\'hash\']","hash"));'."\n".
										t(7).'if (!empty($result["attribute"]))'."\n".
										t(7).'{'."\n".
											t(8).'$types[$k] = "password";'."\n".
											t(8).'break;'."\n".
										t(7).'}'."\n".
									t(6).'}'."\n".
						        t(5).'}'."\n".
						        t(5).'$src .= \'</tr>\';'."\n".
						        t(5).'for($i=0 ; $i<$count=count($entities) ; $i++)'."\n".
						        t(5).'{'."\n".
							        t(6).'$src .= \'<tr>\';'."\n".
							        t(6).'for($j=0 ; $j<$count2 = count($columns) ; $j++)'."\n".
							        t(6).'{'."\n".
								        t(7).'switch ($types[$j])'."\n".
								        t(7).'{'."\n".
									        t(8).'case "password":'."\n".
										        t(9).'$entities[$i]->$columns[$j] = "********";'."\n".
										        t(9).'break;'."\n".
									        t(8).'case "url":'."\n".
										        t(9).'$entities[$i]->$columns[$j] = (SLS_String::isValidUrl($entities[$i]->$columns[$j])) ? "<a href=\'".$entities[$i]->$columns[$j]."\' target=\'_blank\'>".$entities[$i]->$columns[$j]."</a>" : "";'."\n".
										        t(9).'break;'."\n".
									        t(8).'case "file_all":'."\n".
										        t(9).'$entities[$i]->$columns[$j] = (!is_dir($this->_generic->getPathConfig("files").$entities[$i]->$columns[$j]) && file_exists($this->_generic->getPathConfig("files").$entities[$i]->$columns[$j])) ? "<a href=\'http://".$this->_generic->getSiteConfig("domainName")."/".$this->_generic->getPathConfig("files").$entities[$i]->$columns[$j]."?".uniqid()."\' target=\'_blank\'>".$entities[$i]->$columns[$j]."</a>" : "";'."\n".
										        t(9).'break;'."\n".
									        t(8).'case "file_img":'."\n".
										        t(9).'$entities[$i]->$columns[$j] = (!is_dir($this->_generic->getPathConfig("files").$entities[$i]->$columns[$j]) && file_exists($this->_generic->getPathConfig("files").$entities[$i]->$columns[$j])) ? "<a href=\'http://".$this->_generic->getSiteConfig("domainName")."/".$this->_generic->getPathConfig("files").$entities[$i]->$columns[$j]."?".uniqid()."\' target=\'_blank\'><img src=\'http://".$this->_generic->getSiteConfig("domainName")."/".$this->_generic->getPathConfig("files").$entities[$i]->$columns[$j]."?".uniqid()."\' alt=\'".$entities[$i]->$columns[$j]."\' width=\'80\' style=\'max-width:80px;\' /></a>" : "";'."\n".
										        t(9).'break;'."\n".
									        t(8).'case "email":'."\n".
										        t(9).'$entities[$i]->$columns[$j] = "<a href=\'mailto:".$entities[$i]->$columns[$j]."\' target=\'_blank\'>".$entities[$i]->$columns[$j]."</a>";'."\n".
										        t(9).'break;'."\n".
								        t(7).'}'."\n".
								        t(7).'$src .= \'<td style="border:1px solid gray">\'.(($entities[$i]->$columns[$j] == "") ? "&nbsp;" : $entities[$i]->$columns[$j]).\'</td>\';'."\n".
							        t(6).'}'."\n".
							        t(6).'$src .= \'</tr>\';'."\n".
						        t(5).'}'."\n".
						        t(5).'$src .= \'</table></body></html>\';'."\n".
						        t(5).'echo $src;'."\n".
						        t(5).'die();'."\n".
						        t(5).'break;'."\n".
					        t(4).'case "html":'."\n".
						        t(5).'$title = $object->getTableComment($model,$db)." Listing";'."\n".
						        t(5).'header("Content-Type: text/html");'."\n".
						        t(5).'header("Content-Disposition: attachment; filename=\"".$title."\".html");'."\n".
						        t(5).'$src = \'<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body style="font-family:\\\'Franklin Gothic Book\\\', Verdana, Helvetica, Arial;"><table cellpadding="5" cellspacing="0">\';'."\n".
						        t(5).'$src .= \'<tr>\';'."\n".
						        t(5).'$tables = array($object->getTable());'."\n".
						        t(5).'foreach($join as $cur_join)'."\n".
						        	t(6).'array_push($tables,(is_array($cur_join)) ? $cur_join["table"] : $cur_join);'."\n".
						        t(5).'for($k=0 ; $k<$count3=count($columns) ; $k++)'."\n".
						        t(5).'{'."\n".
							        t(6).'$description = $object->getColumnComment($columns[$k],$model,$db);'."\n".
							        t(6).'if ($description == $columns[$k] && !empty($join))'."\n".
							        	t(7).'$description = $object->getColumnComment($columns[$k],$join[0],$db);'."\n".
							        t(6).'$src .= \'<td style="text-align:center;background-color:#CAC3ED;color:#100F16;border:1px solid gray;font-weight:bold;font-size:14px;">\'.$description.\'</td>\';'."\n\n".									
									t(6).'foreach($tables as $table)'."\n".
									t(6).'{'."\n".
										t(7).'// Search possible types'."\n".
										t(7).'$result = array_shift($xmlType->getTagsAttribute("//sls_configs/entry[@table=\'".$object->getDatabase()."_".$table."\' and @column=\'".$columns[$k]."\' and (@type = \'file_img\' or @type = \'file_all\' or @type = \'email\' or @type = \'url\')]","type"));'."\n".
										t(7).'if (!empty($result["attribute"]))'."\n".
										t(7).'{'."\n".
											t(8).'$types[$k] = $result["attribute"];'."\n".
											t(8).'break;'."\n".
										t(7).'}'."\n".
										t(7).'else'."\n".
											t(8).'$types[$k] = "";'."\n\n".										    
										t(7).'// Search possible filters'."\n".
										t(7).'$result = array_shift($xmlFilter->getTagsAttribute("//sls_configs/entry[@table=\'".$object->getDatabase()."_".$table."\' and @column=\'".$columns[$k]."\' and @filter=\'hash\']","hash"));'."\n".
										t(7).'if (!empty($result["attribute"]))'."\n".
										t(7).'{'."\n".
											t(8).'$types[$k] = "password";'."\n".
											t(8).'break;'."\n".
										t(7).'}'."\n".
									t(6).'}'."\n".
						        t(5).'}'."\n".
						        t(5).'$src .= \'</tr>\';'."\n".
						        t(5).'for($i=0 ; $i<$count=count($entities) ; $i++)'."\n".
						        t(5).'{'."\n".
							        t(6).'$src .= \'<tr>\';'."\n".
							        t(6).'for($j=0 ; $j<$count2 = count($columns) ; $j++)'."\n".
							        t(6).'{'."\n".
								        t(7).'switch ($types[$j])'."\n".
								        t(7).'{'."\n".
									        t(8).'case "password":'."\n".
										        t(9).'$entities[$i]->$columns[$j] = "********";'."\n".
										        t(9).'break;'."\n".
									        t(8).'case "url":'."\n".
										        t(9).'$entities[$i]->$columns[$j] = (SLS_String::isValidUrl($entities[$i]->$columns[$j])) ? "<a href=\'".$entities[$i]->$columns[$j]."\' target=\'_blank\'>".$entities[$i]->$columns[$j]."</a>" : "";'."\n".
										        t(9).'break;'."\n".
									        t(8).'case "file_all":'."\n".
										        t(9).'$entities[$i]->$columns[$j] = (!is_dir($this->_generic->getPathConfig("files").$entities[$i]->$columns[$j]) && file_exists($this->_generic->getPathConfig("files").$entities[$i]->$columns[$j])) ? "<a href=\'http://".$this->_generic->getSiteConfig("domainName")."/".$this->_generic->getPathConfig("files").$entities[$i]->$columns[$j]."?".uniqid()."\' target=\'_blank\'>".$entities[$i]->$columns[$j]."</a>" : "";'."\n".
										        t(9).'break;'."\n".
									        t(8).'case "file_img":'."\n".
										        t(9).'$entities[$i]->$columns[$j] = (!is_dir($this->_generic->getPathConfig("files").$entities[$i]->$columns[$j]) && file_exists($this->_generic->getPathConfig("files").$entities[$i]->$columns[$j])) ? "<a href=\'http://".$this->_generic->getSiteConfig("domainName")."/".$this->_generic->getPathConfig("files").$entities[$i]->$columns[$j]."?".uniqid()."\' target=\'_blank\'><img src=\'http://".$this->_generic->getSiteConfig("domainName")."/".$this->_generic->getPathConfig("files").$entities[$i]->$columns[$j]."?".uniqid()."\' alt=\'".$entities[$i]->$columns[$j]."\' style=\'max-width:80px;\' /></a>" : "";'."\n".
										        t(9).'break;'."\n".
									        t(8).'case "email":'."\n".
										        t(9).'$entities[$i]->$columns[$j] = "<a href=\'mailto:".$entities[$i]->$columns[$j]."\' target=\'_blank\'>".$entities[$i]->$columns[$j]."</a>";'."\n".
										        t(9).'break;'."\n".
								        t(7).'}'."\n".
								        t(7).'$src .= \'<td style="border:1px solid gray">\'.(($entities[$i]->$columns[$j] == "") ? "&nbsp;" : $entities[$i]->$columns[$j]).\'</td>\';'."\n".
							        t(6).'}'."\n".
							        t(6).'$src .= \'</tr>\';'."\n".
						        t(5).'}'."\n".
						        t(5).'$src .= \'</table></body></html>\';'."\n".
						        t(5).'echo $src;'."\n".
						        t(5).'die();'."\n".
					        	t(5).'break;'."\n".
					        t(4).'case "csv":'."\n".
						        t(5).'$title = $object->getTableComment($model,$db)." Listing";'."\n".
						        t(5).'header("Content-Type: text/csv");'."\n".
						        t(5).'header("Content-Disposition: attachment; filename=\"".$title."\".csv");'."\n".
						        t(5).'$src = \'\';'."\n".
						        t(5).'for($k=0 ; $k<$count3=count($columns) ; $k++)'."\n".
						        t(5).'{'."\n".
							        t(6).'$description = $object->getColumnComment($columns[$k],$model,$db);'."\n".
							        t(6).'if ($description == $columns[$k] && !empty($join))'."\n".
							        	t(7).'$description = $object->getColumnComment($columns[$k],$join[0],$db);'."\n".
							        t(6).'$src .= str_replace(",","\,",$description);'."\n".
							        t(6).'if ($k < ($count3-1))'."\n".
							        	t(7).'$src .= \';\';'."\n\n".			
									t(6).'// Search possible types'."\n".
							        t(6).'$result = array_shift($xmlType->getTagsAttribute("//sls_configs/entry[@table=\'".$object->getDatabase()."_".$object->getTable()."\' and @column=\'".$columns[$k]."\' and (@type = \'file_img\' or @type = \'file_all\' or @type = \'url\')]","type"));'."\n".
							        t(6).'$types[$k] = (!empty($result["attribute"])) ? $result["attribute"] : "";'."\n\n".			                       
							        t(6).'// Search possible filters'."\n".
									t(6).'$result = array_shift($xmlFilter->getTagsAttribute("//sls_configs/entry[@table=\'".$object->getDatabase()."_".$table."\' and @column=\'".$columns[$k]."\' and @filter=\'hash\']","hash"));'."\n".
									t(6).'$types[$k] = (!empty($result["attribute"])) ? "password" : "";'."\n".
						        t(5).'}'."\n".
						        t(5).'$src .= "\n";'."\n".
						        t(5).'for($i=0 ; $i<$count=count($entities) ; $i++)'."\n".
						        t(5).'{'."\n".
							        t(6).'for($j=0 ; $j<$count2=count($columns) ; $j++)'."\n".
							        t(6).'{'."\n".
								        t(7).'switch ($types[$j])'."\n".
								        t(7).'{'."\n".
									        t(8).'case "password":'."\n".
										        t(9).'$entities[$i]->$columns[$j] = "********";'."\n".
										        t(9).'break;'."\n".
									        t(8).'case "url":'."\n".
										        t(9).'$entities[$i]->$columns[$j] = (SLS_String::isValidUrl($entities[$i]->$columns[$j])) ? $entities[$i]->$columns[$j] : "";'."\n".
										        t(9).'break;'."\n".
									        t(8).'case "file_all":'."\n".
										        t(9).'$entities[$i]->$columns[$j] = (!is_dir($this->_generic->getPathConfig("files").$entities[$i]->$columns[$j]) && file_exists($this->_generic->getPathConfig("files").$entities[$i]->$columns[$j])) ? "http://".$this->_generic->getSiteConfig("domainName")."/".$this->_generic->getPathConfig("files").$entities[$i]->$columns[$j] : "";'."\n".
										        t(9).'break;'."\n".
									        t(8).'case "file_img":'."\n".
										        t(9).'$entities[$i]->$columns[$j] = (!is_dir($this->_generic->getPathConfig("files").$entities[$i]->$columns[$j]) && file_exists($this->_generic->getPathConfig("files").$entities[$i]->$columns[$j])) ? "http://".$this->_generic->getSiteConfig("domainName")."/".$this->_generic->getPathConfig("files").$entities[$i]->$columns[$j] : "";'."\n".
										        t(9).'break;'."\n".
								        t(7).'}'."\n".
								        t(7).'$src .= \'"\'.str_replace(array(\'"\',"\n","\t","\r"),array(\'""\',\'\',\'\',\'\'),$entities[$i]->$columns[$j]).\'"\';'."\n".
								        t(7).'if ($j < ($count2-1))'."\n".
								        	t(8).'$src .= \';\';'."\n".
							        t(6).'}'."\n".
							        t(6).'$src .= "\n";'."\n".
						        t(5).'}'."\n".
						        t(5).'echo $src;'."\n".
						        t(5).'die();'."\n".
						        t(5).'break;'."\n".
					        t(4).'case "txt":'."\n".
						        t(5).'$title = $object->getTableComment($model,$db)." Listing";'."\n".
						        t(5).'header("Content-Type: text/tab-separated-value");'."\n".
						        t(5).'header("Content-Disposition: attachment; filename=\"".$title."\".tsv");'."\n".
						        t(5).'$src = \'\';'."\n".
						        t(5).'for($k=0 ; $k<$count3=count($columns) ; $k++)'."\n".
						        t(5).'{'."\n".
							        t(6).'$description = $object->getColumnComment($columns[$k],$model,$db);'."\n".
							        t(6).'if ($description == $columns[$k] && !empty($join))'."\n".
							        	t(7).'$description = $object->getColumnComment($columns[$k],$join[0],$db);'."\n".
							        t(6).'$src .= $description;'."\n".
							        t(6).'if ($k < ($count3-1))'."\n".
							        	t(7).'$src .= "\t";'."\n\n".			
									t(6).'// Search possible types'."\n".
							        t(6).'$result = array_shift($xmlType->getTagsAttribute("//sls_configs/entry[@table=\'".$object->getDatabase()."_".$object->getTable()."\' and @column=\'".$columns[$k]."\' and (@type = \'file_img\' or @type = \'file_all\' or @type = \'password\' or @type = \'url\')]","type"));'."\n".
							        t(6).'$types[$k] = (!empty($result["attribute"])) ? $result["attribute"] : "";'."\n".
						        t(5).'}'."\n".
						        t(5).'$src .= "\n";'."\n".
						        t(5).'for($i=0 ; $i<$count=count($entities) ; $i++)'."\n".
						        t(5).'{'."\n".
							        t(6).'for($j=0 ; $j<$count2=count($columns) ; $j++)'."\n".
							        t(6).'{'."\n".
								        t(7).'switch ($types[$j])'."\n".
								        t(7).'{'."\n".
									        t(8).'case "password":'."\n".
										        t(9).'$entities[$i]->$columns[$j] = "********";'."\n".
										        t(9).'break;'."\n".
									        t(8).'case "url":'."\n".
										        t(9).'$entities[$i]->$columns[$j] = (SLS_String::isValidUrl($entities[$i]->$columns[$j])) ? $entities[$i]->$columns[$j] : "";'."\n".
										        t(9).'break;'."\n".
									        t(8).'case "file_all":'."\n".
										        t(9).'$entities[$i]->$columns[$j] = (!is_dir($this->_generic->getPathConfig("files").$entities[$i]->$columns[$j]) && file_exists($this->_generic->getPathConfig("files").$entities[$i]->$columns[$j])) ? "http://".$this->_generic->getSiteConfig("domainName")."/".$this->_generic->getPathConfig("files").$entities[$i]->$columns[$j] : "";'."\n".
										        t(9).'break;'."\n".
									        t(8).'case "file_img":'."\n".
										        t(9).'$entities[$i]->$columns[$j] = (!is_dir($this->_generic->getPathConfig("files").$entities[$i]->$columns[$j]) && file_exists($this->_generic->getPathConfig("files").$entities[$i]->$columns[$j])) ? "http://".$this->_generic->getSiteConfig("domainName")."/".$this->_generic->getPathConfig("files").$entities[$i]->$columns[$j] : "";'."\n".
										        t(9).'break;'."\n".
								        t(7).'}'."\n".
								        t(7).'$src .= $entities[$i]->$columns[$j];'."\n".
								        t(7).'if ($j < ($count2-1))'."\n".
								        	t(8).'$src .= "\t";'."\n".
							        t(6).'}'."\n".
							        t(6).'$src .= "\n";'."\n".
						        t(5).'}'."\n".
						        t(5).'echo $src;'."\n".
						        t(5).'die();'."\n".
			        		t(5).'break;'."\n".
			        t(3).'}'."\n".
			        t(2).'}'."\n";
		
		$source = substr($source,0,strpos($source,"action()")+8)."\n".
				  t(1).'{'."\n".
				  $action.
				  t(1).'}'."\n".
				  '}'."\n".
				  '?>';
		
		file_put_contents($this->_generic->getPathConfig("actionsControllers").$controllerBo."/Export.controller.php",$source);
	}
	
	/**
	 * Create bo action disconnection
	 *
	 * @param string $controllerBo generic controller name (Bo)
	 */
	protected function createActionBoDisconnection($controllerBo="")
	{
		$langs = $this->_generic->getObjectLang()->getSiteLangs();		
		$params = array(0 => array("key" 	=> "reload",
				  				   "value" 	=> "true"),
				  		1 => array("key" 	=> "Controller",
				  				   "value" 	=> $controllerBo),
					 	2 => array("key" 	=> "actionName",
				  				   "value" 	=> "Disconnection"),
				  		3 => array("key"	=> "token",
				  				   "value"	=> sha1(substr($this->_generic->getSiteConfig("privateKey"), 0, 3).substr($this->_generic->getSiteConfig("privateKey"), strlen($this->_generic->getSiteConfig("privateKey"))-3)),
				  		4 => array("key"	=> "indexes",
				  				   "value"	=> "noindex,nofollow")
				  			)
					    );
		foreach($langs as $lang)
		{
			$tmpParam = array("key" 	=> $lang."-action",
							  "value" 	=> "Disconnection");
			$tmpTitle = array("key" 	=> $lang."-title",
							  "value" 	=> "Disconnection");
			array_push($params,$tmpParam);
			array_push($params,$tmpTitle);
		}
		file_get_contents($this->_generic->getFullPath("SLS_Bo",
													  "AddAction",
													  $params,
													  true));
										  
		$source = file_get_contents($this->_generic->getPathConfig("actionsControllers").$controllerBo."/Disconnection.controller.php");
		
		$action = t(2).'SLS_BoRights::disconnect();'."\n".
        		  t(2).'$this->_generic->redirect("'.$controllerBo.'/Connection.sls");'."\n";
		$source = substr($source,0,strpos($source,"action()")+8)."\n".
				  '    {'."\n".
				  $action.
				  '    }'."\n".
				  '}'."\n".
				  '?>';
		
		file_put_contents($this->_generic->getPathConfig("actionsControllers").$controllerBo."/Disconnection.controller.php",$source);
	}
	
	/**
	 * Create bo action deletefile
	 *
	 * @param string $controllerBo generic controller name (Bo)
	 */
	protected function createActionBoDeleteFile($controllerBo="")
	{
		$langs = $this->_generic->getObjectLang()->getSiteLangs();		
		$params = array(0 => array("key" 	=> "reload",
				  				   "value" 	=> "true"),
				  		1 => array("key" 	=> "Controller",
				  				   "value" 	=> $controllerBo),
					 	2 => array("key" 	=> "actionName",
				  				   "value" 	=> "DeleteFile"),
				  		3 => array("key"	=> "token",
				  				   "value"	=> sha1(substr($this->_generic->getSiteConfig("privateKey"), 0, 3).substr($this->_generic->getSiteConfig("privateKey"), strlen($this->_generic->getSiteConfig("privateKey"))-3)),
				  		4 => array("key"	=> "indexes",
				  				   "value"	=> "noindex,nofollow")
				  			)
					    );
		foreach($langs as $lang)
		{
			$tmpParam = array("key" 	=> $lang."-action",
							  "value" 	=> "DeleteFile");
			$tmpTitle = array("key" 	=> $lang."-title",
							  "value" 	=> "DeleteFile");
			array_push($params,$tmpParam);
			array_push($params,$tmpTitle);
		}
		file_get_contents($this->_generic->getFullPath("SLS_Bo",
													  "AddAction",
													  $params,
													  true));
													  
		$source = file_get_contents($this->_generic->getPathConfig("actionsControllers").$controllerBo."/DeleteFile.controller.php");
		
		$action = t(2).'// Params'."\n".
				  t(2).'$action = $this->_http->getParam("action");'."\n".
				  t(2).'$id 	= $this->_http->getParam("id");'."\n".
				  t(2).'$db 	= $this->_http->getParam("db");'."\n".
				  t(2).'$table 	= $this->_http->getParam("table");'."\n".
				  t(2).'$column = $this->_http->getParam("column");'."\n".
				  t(2).'$type 	= $this->_http->getParam("type");'."\n\n".		
				  t(2).'// Check account rights'."\n".
        		  t(2).'$right = SLS_BoRights::isAuthorized("delete",ucfirst($db)."_".SLS_String::tableToClass($table));'."\n".
        		  t(2).'if ($right == -1)'."\n".
        		  t(3).'$this->_generic->redirect("Bo/Connection.sls");'."\n".
        		  t(2).'else if ($right == 0)'."\n".
        		  t(3).'$this->_generic->redirect("Bo/".ucfirst(strtolower($action)).ucfirst($db)."_".SLS_String::tableToClass($table)."/id/".$id.".sls");'."\n".
        		  t(2).'// /Check account rights'."\n\n".        
        		  t(2).'// Delete specific type files'."\n".
        		  t(2).'$this->_generic->useModel($table,$db);'."\n".
        		  t(2).'$className = ucfirst($db)."_".SLS_String::tableToClass($table);'."\n".
        		  t(2).'$object = new $className();'."\n".
        		  t(2).'if ($object->getModel($id))'."\n".
				  t(2).'{'."\n".
				  t(3).'$object->deleteFiles(array($column));'."\n".
				  t(3).'$functionName = "set".SLS_String::fullTrim(ucwords(SLS_String::stringToUrl(str_replace("_"," ",$column)," ",false)),"");'."\n".       	
        		  t(3).'$object->{$functionName}("");'."\n".
        		  t(3).'$object->save();'."\n".       			  
				  t(2).'}'."\n\n".  
       			  t(2).'// Forward'."\n".
        		  t(2).'$this->_generic->redirect("Bo/".ucfirst(strtolower($action)).ucfirst($db)."_".SLS_String::tableToClass($table)."/id/".$id.".sls");'."\n";
		$source = substr($source,0,strpos($source,"action()")+8)."\n".
				  '    {'."\n".
				  $action.
				  '    }'."\n".
				  '}'."\n".
				  '?>';
		
		file_put_contents($this->_generic->getPathConfig("actionsControllers").$controllerBo."/DeleteFile.controller.php",$source);
	}
	
	/**
	 * Create bo action FkAC
	 *
	 * @param string $controllerBo generic controller name (Bo)
	 */
	protected function createActionBoFkAC($controllerBo="")
	{
		$langs = $this->_generic->getObjectLang()->getSiteLangs();		
		$params = array(0 => array("key" 	=> "reload",
				  				   "value" 	=> "true"),
				  		1 => array("key" 	=> "Controller",
				  				   "value" 	=> $controllerBo),
					 	2 => array("key" 	=> "actionName",
				  				   "value" 	=> "FkAC"),
				  		3 => array("key"	=> "token",
				  				   "value"	=> sha1(substr($this->_generic->getSiteConfig("privateKey"), 0, 3).substr($this->_generic->getSiteConfig("privateKey"), strlen($this->_generic->getSiteConfig("privateKey"))-3)),
				  		4 => array("key"	=> "indexes",
				  				   "value"	=> "noindex,nofollow")
				  			)
					    );
		foreach($langs as $lang)
		{
			$tmpParam = array("key" 	=> $lang."-action",
							  "value" 	=> "FkAC");
			$tmpTitle = array("key" 	=> $lang."-title",
							  "value" 	=> "FkAC");
			array_push($params,$tmpParam);
			array_push($params,$tmpTitle);
		}
		file_get_contents($this->_generic->getFullPath("SLS_Bo",
													  "AddAction",
													  $params,
													  true));
													  
		$source = file_get_contents($this->_generic->getPathConfig("actionsControllers").$controllerBo."/FkAC.controller.php");
		
		$action = t(2).'$xml = $this->getXML();'."\n\n".                
		          t(2).'// Check account rights'."\n".
		          t(2).'$right = SLS_BoRights::isAuthorized("add",ucfirst($this->_http->getParam("Db"))."_".$this->_http->getParam("Model"));'."\n".        
		          t(2).'if ($right == -1)'."\n".
		          t(3).'$this->_generic->redirect("Bo/Connection.sls");'."\n".
		          t(2).'else if ($right == 0)'."\n".
		          t(3).'$this->_generic->redirect("Bo/Connection.sls");'."\n".
		          t(2).'// /Check account rights'."\n\n".        
		          t(2).'// Params'."\n".
		          t(2).'$model 	= $this->_http->getParam("Model");'."\n".
		          t(2).'$db 	= $this->_http->getParam("Db");'."\n".
		          t(2).'$column = $this->_http->getParam("Column");'."\n".
		          t(2).'$keyword= $this->_http->getParam("Keyword");'."\n".
		          t(2).'$lang 	= $this->_http->getParam("Lang");'."\n".
		          t(2).'$id 	= $this->_http->getParam("Id");'."\n\n".
		          t(2).'// Objects'."\n".
		          t(2).'$this->_generic->useModel(SLS_String::tableToClass($model),$db,"user");'."\n".
				  t(2).'$class = ucfirst($db)."_".SLS_String::tableToClass($model);'."\n".
				  t(2).'$currentModel = new $class();'."\n\n".        
		          t(2).'// Check really fk'."\n".
		          t(2).'$xmlFk = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml"));'."\n".
		          t(2).'$res = $xmlFk->getTagsByAttributes("//sls_configs/entry",array("tableFk","columnFk"),array($db."_".$currentModel->getTable(),$column));'."\n".				
				  t(2).'if (empty($res))'."\n".
				  t(3).'$this->_generic->redirect("Bo/Connection.sls");'."\n\n".		
				  t(2).'// Objects'."\n".
				  t(2).'$resultFk = array_shift($xmlFk->getTagsAttribute("//sls_configs/entry[@tableFk=\'".$db."_".$currentModel->getTable()."\' and @columnFk=\'".$column."\' and @multilanguage = \'false\']","multilanguage"));'."\n".
				  t(2).'$labelPk = substr($res,(strpos($res,\'labelPk="\')+9),(strpos($res,\'" tablePk="\')-(strpos($res,\'labelPk="\')+9)));'."\n".
				  t(2).'$tableTm = substr($res,(strpos($res,\'tablePk="\')+9),(strpos($res,\'"/>\')-(strpos($res,\'tablePk="\')+9)));'."\n".
				  t(2).'$tablePk = SLS_String::substrAfterFirstDelimiter($tableTm,"_");'."\n".
				  t(2).'$dbPk 	 = SLS_String::substrBeforeFirstDelimiter($tableTm,"_");'."\n".
		          t(2).'$this->_generic->useModel($tablePk,$dbPk,"user");'."\n".
				  t(2).'$classFk = ucfirst($dbPk)."_".SLS_String::tableToClass($tablePk);'."\n".
				  t(2).'$objectFk = new $classFk();'."\n".
				  t(2).'$columns = array();'."\n".
				  t(2).'$columnsLabel = array();'."\n".
				  t(2).'$clause = array();'."\n".
				  t(2).'$render = array();'."\n".
				  t(2).'foreach($objectFk->getParams() as $key => $value)'."\n".
				  t(2).'{'."\n".
				  t(3).'array_push($columns,"`".$key."`");'."\n".
				  t(3).'if (SLS_String::contains($labelPk,$key))'."\n".
				  t(4).'$columnsLabel[$key] = strpos($labelPk,$key);'."\n".				
				  t(2).'}'."\n".
				  t(2).'array_multisort($columnsLabel);'."\n".
				  t(2).'foreach($columnsLabel as $columnLabel => $offset)'."\n".
				  t(3).'array_push($clause,$columnLabel);'."\n".
				  t(2).'$pattern = str_replace("\'","\'\'",$labelPk);'."\n".
        		  t(2).'foreach($clause as $columnC)'."\n".
        		  t(3).'$pattern = str_replace($columnC,"\',".$columnC.",\'",$pattern);'."\n\n".					
				  t(2).'$results = $currentModel->fkAC($currentModel->getTable(),$objectFk->getTable(),$objectFk->getPrimaryKey(),$columns,"CONCAT(\'".$pattern."\')",($objectFk->isMultilanguage()) ? $lang : "",implode(\'%\',explode(\' \',trim($keyword))),10,$id);'."\n".
				  t(2).'for($i=0 ; $i<$count=count($results) ; $i++)'."\n".
				  t(2).'{'."\n".
				  t(3).'$mask = $labelPk;'."\n".
				  t(3).'$id = 0;'."\n".
				  t(3).'$label = "";'."\n".
				  t(3).'foreach($results[$i] as $key => $value)'."\n".
				  t(3).'{'."\n".
				  t(4).'if ($key == $objectFk->getPrimaryKey())'."\n".
				  t(5).'$id = $value;'."\n".
				  t(4).'if (SLS_String::contains($mask,$key))'."\n".
				  t(5).'$mask = str_replace($key,$value,$mask);'."\n".
				  t(3).'}'."\n".
				  t(3).'array_push($render,array("id"=>$id,"label"=>$mask));'."\n".
				  t(2).'}'."\n\n".
				  t(2).'echo json_encode($render);'."\n".
				  t(2).'die();'."\n";
		$source = substr($source,0,strpos($source,"action()")+8)."\n".
				  t(1).'{'."\n".
				  $action.
				  t(1).'}'."\n".
				  '}'."\n".
				  '?>';
		
		file_put_contents($this->_generic->getPathConfig("actionsControllers").$controllerBo."/FkAC.controller.php",$source);
	}
	
	/**
	 * Delete a action bo
	 *
	 * @param string $model the model described the bo
	 * @param string $actionType the action you want to delete ('list'|'add'|'modify'|'delete'|'clone'|'email')
	 * @param string $alias the alias of the db
	 * @return bool true if ok, else false
	 */
	protected function deleteActionBo($model,$actionType="list",$alias)
	{		
		$controllersXML = $this->_generic->getControllersXML();
		$controller = array_shift($controllersXML->getTags("//controllers/controller[@isBo='true']/@name"));
		$actionTypes = array("list","add","modify","delete","clone","email");
		if (!in_array($actionType,$actionTypes) || empty($controller))
			return false;
		$params = array(0 => array("key" 	=> "reload",
				  				   "value" 	=> "true"),
				  		1 => array("key" 	=> "Controller",
				  				   "value" 	=> $controller),
					 	2 => array("key" 	=> "Action",
				  				   "value" 	=> ucfirst($actionType).ucfirst($alias)."_".ucfirst($model)),
				  		3 => array(
				  					"key"	=> "token",
				  					"value"	=> sha1(substr($this->_generic->getSiteConfig("privateKey"), 0, 3).substr($this->_generic->getSiteConfig("privateKey"), strlen($this->_generic->getSiteConfig("privateKey"))-3))
				  			)
					    );		
		file_get_contents($this->_generic->getFullPath("SLS_Bo",
													  "DeleteAction",
													  $params,
													  true));
		return true;
	}
	
	/**
	 * Just copy all actions langs files from given controllers
	 *
	 * @param array $controllers a list of all controllers in which we want to copy actions
	 * @param string $lang the iso code of the new lang
	 */
	protected function copyActionsLang($controllers=array(),$iso)
	{
		if (!empty($controllers) && !empty($iso))
		{
			$actions = array();
			
			foreach($controllers as $controller)
			{
				$handle = opendir($this->_generic->getPathConfig("actionLangs").$controller);
				while (false !== ($file = readdir($handle)))
					if (!is_dir($this->_generic->getPathConfig("actionLangs").$controller."/".$file) && substr($file, 0, 1) != ".")
						if (!in_array(SLS_String::substrBeforeFirstDelimiter($file,"."),$actions))
							array_push($actions,SLS_String::substrBeforeFirstDelimiter($file,"."));
				
				foreach($actions as $action)				
					file_put_contents($this->_generic->getPathConfig("actionLangs").$controller."/".$action.".".$iso.".lang.php",file_get_contents($this->_generic->getPathConfig("actionLangs").$controller."/".$action.".".$this->_generic->getSiteConfig("defaultLang").".lang.php"));
				$actions = array();
			}
		}
	}
	
	/**
	 * Delete all actions lang files from given lang
	 *
	 * @param string $root the path to list
	 * @param string $iso the lang
	 */
	protected function deleteActionsLang($root,$iso)
	{
		$handle = opendir($root);
		while (false !== ($file = readdir($handle)))
		{
			// Recursive call			
			if (is_dir($root."/".$file)  && substr($file, 0, 1) != ".")				
				$this->deleteActionsLang($root."/".$file,$iso);
			// Check if file in correct lang, if yes, delete it !
			if (!is_dir($root."/".$file) && substr($file, 0, 1) != ".")				
				if (SLS_String::endsWith($file,".".$iso.".lang.php"))
					@unlink($root."/".$file);
		}
	}
	
	/**
	 * Get all the application templates
	 *
	 * @return array
	 */
	protected function getAppTpls()
	{
		$tpls = array();		
	
		$handle = opendir($this->_generic->getPathConfig("viewsTemplates"));
		while($file = readdir($handle))
		{
			if (is_file($this->_generic->getPathConfig("viewsTemplates").$file) && substr($file, 0, 1) != ".")
			{
				$fileName 	= SLS_String::substrBeforeLastDelimiter($file,".");
				$extension 	= SLS_String::substrAfterLastDelimiter($file,".");
				
				if ($extension == "xsl")				
					array_push($tpls,$fileName);				
			}
		}
		closedir($handle);
		
		return $tpls;
	}
	
	/**
	 * Get all the application xsl
	 *
	 * @return array
	 */
	protected function getAppXsl($path="",$generics = array())
	{
		$paths = (empty($path)) ? array($this->_generic->getPathConfig("views"),$this->_generic->getPathConfig("coreViews")) : array($path);
		
		foreach($paths as $path)
		{
			$handle = opendir($path);
			while($file = readdir($handle))
			{
				if (is_file($path.$file) && substr($file, 0, 1) != ".")
				{
					$fileName 	= SLS_String::substrBeforeLastDelimiter($file,".");
					$extension 	= SLS_String::substrAfterLastDelimiter($file,".");
					
					if ($extension == "xsl")
					{
						if (!in_array(strtolower($fileName),$generics))
							array_push($generics,strtolower($fileName));
						
						$content = file_get_contents($path.$file);
						preg_match_all('/<xsl:template name="(.*)">/', $content, $matches);
						if (is_array($matches) && count($matches) > 1)
							foreach($matches[1] as $match)
								if (!in_array(strtolower($match),$generics))
									array_push($generics,strtolower($match));
					}				
				}
				else if (is_dir($path.$file) && substr($file, 0, 1) != ".")
					$generics = $this->getAppXsl($path.$file."/",$generics);
			}
			closedir($handle);
		}
		
		return $generics;
	}
	
	/**
	 * Get the source code of a model from his table
	 * 
	 * @param string $tableName the table name 
	 * @param string $db the alias of the database on which the model is located
	 * @return string $contentM the source code
	 */
	protected function getModelSource($tableName,$db)
	{
		$arrayConvertTypes = array(
			'varchar'	=>	'string',
			'tinyint'	=>	'int',
			'text'		=>	'string',
			'date'		=>	'string',
			'smallint'	=>	'int',
			'mediumint'	=>	'int',
			'int'		=>	'int',
			'bigint'	=>	'int',
			'float'		=>	'float | int',
			'double'	=>	'float | int',
			'decimal'	=>	'float',
			'datetime'	=>	'string',
			'timestamp'	=>	'int',
			'time'		=>	'string | int',
			'year'		=>	'int',
			'char'		=>	'string',
			'tinyblob'	=>	'string',
			'tinytext'	=>	'string',
			'blob'		=>	'string',
			'mediumblob'=>	'string',
			'mediumtext'=>	'string',
			'longblob'	=>	'string',
			'longtext'	=>	'string',
			'enum'		=>	'string',
			'set'		=>	'string',
			'bool'		=>	'int',
			'binary'	=>	'string',
			'varbinary'	=>	'string'
		);
		$sql 		= SLS_Sql::getInstance();
		$className 	= ucfirst($db)."_".SLS_String::tableToClass($tableName);
		$file 		= ucfirst($db).".".SLS_String::tableToClass($tableName);
		
		// Create empty source
		$contentM = "";
		$primaryKey = "";
		$multiLanguage = 'false';
		$columns = $sql->showColumns($tableName);
		$fileName = ucfirst($db).".".SLS_String::tableToClass($tableName).".model.php";
		$primaryKey = "";
		$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/types.xml");
		$xmlType = new SLS_XMLToolbox($pathsHandle);
		$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/fks.xml");
		$xmlFk = new SLS_XMLToolbox($pathsHandle);
		$pathsHandle = file_get_contents($this->_generic->getPathConfig("configSls")."/filters.xml");
		$xmlFilter = new SLS_XMLToolbox($pathsHandle);
		
		// Create Model		
		$contentM = '<?php'."\n".
				   '/**'."\n".
				   ' * Object '.$className.''."\n".
				   ' * @author SillySmart'."\n".
				   ' * @copyright SillySmart'."\n".
				   ' * @package Mvc.Models.Objects'."\n".
				   ' * @see Sls.Models.Core.SLS_FrontModel'."\n".
				   ' * @since 1.0'."\n".
				   ' */'."\n".
				   'class '.$className.' extends SLS_FrontModel'."\n".
				   '{'."\n".
					   t(1).'/**'."\n".
				       t(1).' * Class variables'."\n".
					   t(1).' */'."\n";				   
		$pkFound = false;
		for($i=0 ; $i<$count=count($columns) ; $i++)
		{
			if (!$pkFound && $columns[$i]->Key == "PRI")
			{
				$primaryKey = SLS_String::removePhpChars($columns[$i]->Field);
				$pkFound = true;
			}
			if ($columns[$i]->Field == "pk_lang" && $columns[$i]->Key == "PRI")
				$multiLanguage = 'true';
			$contentM .= t(1).'protected $__'.SLS_String::removePhpChars($columns[$i]->Field).';'."\n";
		}
		
		$contentM .= t(1).'protected $_table = "'.$tableName.'";'."\n".
					 t(1).'protected $_db = "'.$db.'";'."\n".
					 t(1).'protected $_primaryKey = "'.$primaryKey.'";'."\n";
		
		// Get FKs to create access reference functions
		$fks = $xmlFk->getTagsAttributes("//sls_configs/entry[@tableFk='".$db."_".$tableName."']",array("columnFk","tablePk"));
		$fkFunctions = "";
		for($i=0 ; $i<$count=count($fks) ; $i++)
		{
			$tablePk = $fks[$i]["attributes"][1]["value"];
			$functionName = SLS_String::fullTrim(ucwords(SLS_String::stringToUrl(SLS_String::tableToClass(SLS_String::substrAfterFirstDelimiter($tablePk,"_"))," ",false)),"");
			$functionName{0} = strtolower($functionName{0});
			$fkFunctions .= "'".$functionName."'";
			if ($i < ($count - 1))
				$fkFunctions .= ", ";
		}
		
		$contentM .= t(1).'protected $_fks = array('.$fkFunctions.');'."\n";
		
		$contentM .= t(1).'public $_typeErrors = array();'."\n\n".
					 t(1).'/**'."\n".
				     t(1).' * Constructor '.$className.''."\n".
				     t(1).' * @author SillySmart'."\n".
				     t(1).' * @copyright SillySmart'."\n".
				     t(1).' * @param bool $mutlilanguage true if multilanguage content, else false'."\n".
				     t(1).' */'."\n".
					 t(1).'public function __construct($multilanguage='.$multiLanguage.')'."\n".
					 t(1).'{'."\n".
						 t(2).'parent::__construct($multilanguage);'."\n".
						 t(2).'$this->buildDefaultValues();'."\n".
					 t(1).'}'."\n\n";
		
		$contentM .= t(1).'/**'."\n".
				     t(1).' * Build default values for specific columns'."\n".
				     t(1).' * @author SillySmart'."\n".
				     t(1).' * @copyright SillySmart'."\n".
				     t(1).' */'."\n".
					 t(1).'public function buildDefaultValues()'."\n".
					 t(1).'{'."\n";
		
		for($i=0 ; $i<$count=count($columns) ; $i++)
		{
			$columnType = (strpos($columns[$i]->Type, "(")) ? SLS_String::substrBeforeFirstDelimiter(strtolower($columns[$i]->Type), "(") : $columns[$i]->Type;
			$functionName = "set".SLS_String::fullTrim(ucwords(SLS_String::stringToUrl(str_replace("_"," ",SLS_String::removePhpChars($columns[$i]->Field))," ",false)),"");
			
			if ($columns[$i]->Null == "NO")
			{			
				// Dates
				if ($columnType == "date" || $columnType == "datetime" || $columnType == "timestamp" || $columnType == "year" || $columnType == "time")
				{
					switch ($columnType)
					{
						case "date":
							$contentM .= t(2).'$this->__'.$columns[$i]->Field.' = date("Y-m-d");'."\n";
							break;
						case "time":
							$contentM .= t(2).'$this->__'.$columns[$i]->Field.' = date("H:i:s");'."\n";
							break;
						case "datetime":
							$contentM .= t(2).'$this->__'.$columns[$i]->Field.' = date("Y-m-d H:i:s");'."\n";
							break;
						case "timestamp":
							$contentM .= t(2).'$this->__'.$columns[$i]->Field.' = date("Y-m-d H:i:s");'."\n";
							break;
						case "year":
							$contentM .= t(2).'$this->__'.$columns[$i]->Field.' = date("Y");'."\n";
							break;
					}
				}
				
				// Uniqid
				$result = $xmlType->getTags("//sls_configs/entry[@table='".$db."_".$tableName."' and @column='".SLS_String::removePhpChars($columns[$i]->Field)."' and @type='uniqid']");
				if (!empty($result))
				{
					$contentM .= t(2).'$this->__'.$columns[$i]->Field.' = substr(md5(time().substr(sha1(microtime()),0,rand(12,25))),mt_rand(1,20),40);'."\n";
				}
				
				// IP Address
				$result = array_shift($xmlType->getTags("//sls_configs/entry[@table='".$db."_".$tableName."' and @column='".SLS_String::removePhpChars($columns[$i]->Field)."' and (@type='ip_both' or @type='ip_v4' or @type='ip_v6')]/@type"));
				if (!empty($result))
				{
					$contentM .= t(2).'$this->__'.$columns[$i]->Field.' = $_SERVER["REMOTE_ADDR"];'."\n";
				}
			}
		}
		$contentM .= t(1).'}'."\n\n";
		
		for($i=0 ; $i<$count=count($columns) ; $i++)
		{
			$isPassword = false;
			
			if ($columns[$i]->Key != "PRI")
			{
				$column = SLS_String::removePhpChars($columns[$i]->Field);
				$columnType = (strpos($columns[$i]->Type, "(")) ? SLS_String::substrBeforeFirstDelimiter(strtolower($columns[$i]->Type), "(") : $columns[$i]->Type;
				$functionName = "set".SLS_String::fullTrim(ucwords(SLS_String::stringToUrl(str_replace("_"," ",$column)," ",false)),"");
				
				$contentM .= t(1).'/**'."\n".
						     t(1).' * Set the value of '.$column.''."\n".
						     t(1).' * Errors can be catched with the public variable $this->_typeErrors[\''.$column.'\']'."\n".
						     t(1).' * @author SillySmart'."\n".
						     t(1).' * @copyright SillySmart'."\n".
						     t(1).' * @param '.$arrayConvertTypes[$columnType].' $value'."\n".
						     t(1).' * @return bool true if updated, false if not'."\n".
						     t(1).' */'."\n".
							 t(1).'public function '.$functionName.'($value';
				
				if ($columns[$i]->Default !== null)
					$contentM .= '="'.SLS_String::addSlashesToString($columns[$i]->Default,false).'"';
					
				$contentM .= ')'."\n";
				$contentM .= t(1).'{'."\n";
				
				// Nullable case
				if ($columns[$i]->Null == "YES")
				{
					$contentM .= t(2).'if (empty($value))'."\n".
								 t(2).'{'."\n".
									 t(3).'$this->__set(\''.$column.'\', $value);'."\n".
									 t(3).'return true;'."\n".
								 t(2).'}'."\n\n";
				}
				
				// Recover Fk
				$res = $xmlFk->getTagsByAttributes("//sls_configs/entry",array("tableFk","columnFk"),array($db."_".$tableName,$column));
				if (!empty($res))
				{
					$tableTm = substr($res,(strpos($res,'tablePk="')+9),(strpos($res,'"/>')-(strpos($res,'tablePk="')+9)));							
					$tablePk = SLS_String::substrAfterFirstDelimiter($tableTm,"_");
					$dbPk 	 = SLS_String::substrBeforeFirstDelimiter($tableTm,"_");
					$contentM .= 	 t(2).'$this->_generic->useModel("'.SLS_String::tableToClass($tablePk).'","'.$dbPk.'");'."\n".
									 t(2).'$object = new '.ucfirst($dbPk).'_'.SLS_String::tableToClass($tablePk).'();'."\n".
									 t(2).'if ($object->getModel($value) === false)'."\n".										 
									 t(2).'{'."\n".
										 t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_KEY";'."\n".
										 t(3).'return false;'."\n".
									 t(2).'}'."\n".										 
									 t(2).'$this->__set(\''.$column.'\', $value);'."\n".
									 t(2).'return true;'."\n".
								 t(1).'}'."\n\n";
				}
				
				// If not a fk
				else
				{
					// Check filters
					$results = $xmlFilter->getTags("//sls_configs/entry[@table='".$db."_".$tableName."' and @column='".$column."']/@filter");														
					for($j=0 ; $j<$countJ=count($results) ; $j++)
					{									
						switch($results[$j])
						{
							case "hash":
								$isPassword = true;
								$contentM .= t(2).'if (empty($value))'."\n".
										 	 	t(3).'$value = $this->__'.$column.';'."\n";
								break;
							default:
								$contentM .= t(2).'$value = SLS_String::filter($value,"'.$results[$j].'");'."\n";
								break;
						}
					}
					if (count($results) > 0)
						$contentM .= "\n";
					
					$result = $xmlType->getTags("//sls_configs/entry[@table='".$db."_".$tableName."' and @column='".$column."']");
					if (!empty($result))
					{
						$type = "";
						$array = array('color','uniqid','email','ip_both','ip_v4','ip_v6','url','file_all','file_img','position');
						for($j=0 ; $j<count($array) ; $j++)
						{
							$result = $xmlType->getTags("//sls_configs/entry[@table='".$db."_".$tableName."' and @column='".$column."' and @type='".$array[$j]."']");
							if (!empty($result))
							{
								$type = $array[$j];
								switch($type)
								{
									case "position":
										$contentM .= t(2).'if (!is_int(intval($value)) || intval($value) < 0)'."\n".
											         t(2).'{'."\n".
												         t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n".
												         t(3).'return false;'."\n".
											         t(2).'}'."\n\n".
													 t(2).'$qbd = new SLS_QueryBuilder();'."\n".
													 t(2).'$old_'.$column.' = $this->__'.$column.';'."\n".
													 t(2).'if (empty($old_'.$column.'))'."\n".
											         t(2).'{'."\n".
											         	t(3).'$qbd->update()'."\n".
													         t(4).'->from("'.$tableName.'")'."\n".
													         t(4).'->set("`'.$column.'` = `'.$column.'` + 1")'."\n".
													         t(4).'->where($qbd->expr()->gte("'.$column.'",$value))'."\n".
													         t(4).'->execute();'."\n".
											         t(2).'}'."\n".
											         t(2).'else'."\n".
											         t(2).'{'."\n".
												    	 t(3).'if ($old_'.$column.' != $value)'."\n".
												    	 t(3).'{'."\n".
											    		 	t(4).'$qbd->update()'."\n".
													    		 t(5).'->from("'.$tableName.'")'."\n".
													    		 t(5).'->set("`'.$column.'` = `'.$column.'` ".(($old_'.$column.' < $value) ? "-" : "+")." 1")'."\n".
													    		 t(5).'->where($qbd->expr()->{($old_'.$column.' < $value) ? "gt" : "gte"}("'.$column.'",($old_'.$column.' < $value) ? $old_'.$column.' : $value))'."\n".
													    		 t(5).'->whereAnd($qbd->expr()->{($old_'.$column.' < $value) ? "lte" : "lt"}("'.$column.'",($old_'.$column.' < $value) ? $value : $old_'.$column.'))'."\n".
													    		 t(5).'->execute();'."\n".
														 	t(4).'$qbd->update()'."\n".
													    		 t(5).'->from("'.$tableName.'")'."\n".
													    		 t(5).'->set($qbd->expr()->eq("'.$column.'",$value))'."\n".
													    		 t(5).'->where($qbd->expr()->eq("'.$primaryKey.'",$this->__'.$primaryKey.'))'."\n".
													    		 t(5).'->execute();'."\n".
											    		 t(3).'}'."\n".													 
											    	 t(2).'}'."\n\n";
										break;
									case "color":
										$contentM .= t(2).'if (!ctype_xdigit($value))'."\n";
										$contentM .= t(2).'{'."\n".
														 t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n".
														 t(3).'return false;'."\n".
													 t(2).'}'."\n\n";
										break;
									case "uniqid":										
										$contentM .= t(2).'if (empty($value))'."\n".
													 	t(3).'$value = substr(md5(time().substr(sha1(microtime()),0,rand(12,25))),mt_rand(1,20),40);'."\n\n";
										break;
									case "email":
										$contentM .= t(2).'if (!SLS_String::validateEmail($value))'."\n";
										$contentM .= t(2).'{'."\n".
												 		 t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n".
												 		 t(3).'return false;'."\n".
											 		 t(2).'}'."\n\n";
										break;
									case "url":
										$contentM .= t(2).'if (!SLS_String::isValidUrl($value))'."\n";
										$contentM .= t(2).'{'."\n".
												 		 t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n".
												 		 t(3).'return false;'."\n".
											 		 t(2).'}'."\n\n";
										break;
									case (in_array($type,array("ip_both","ip_v4","ip_v6"))):
										$type = SLS_String::substrAfterLastDelimiter($type,"_");
										
										$contentM .= t(2).'if (empty($value))'."\n".
													 	t(3).'$value = $_SERVER["REMOTE_ADDR"];'."\n\n";
										$contentM .= t(2).'if (!SLS_String::isIp($value,"'.$type.'"))'."\n";
										$contentM .= t(2).'{'."\n".
														 t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n".
														 t(3).'return false;'."\n".
													 t(2).'}'."\n\n";												
										break;
									case "file_all":
										$contentM .= t(2).'if (!empty($this->__'.$column.'))'."\n".
													 t(2).'{'."\n".
														 t(3).'$this->deleteFiles(array("'.$column.'"));'."\n".
														 t(3).'$this->__'.$column.' = "__Uploads/__Deprecated/".$this->__'.$column.';'."\n".
														 t(3).'$this->save();'."\n".
													 t(2).'}'."\n\n".
													 t(2).'if (is_array($value))'."\n".
													 t(2).'{'."\n";
										if ($columns[$i]->Null == "YES") 
											$contentM .= t(3).'if ($value["error"] == 4)'."\n".
														 t(3).'{'."\n".
															 t(4).'$this->__set(\''.$column.'\',(empty($this->{__.$column})) ? "" : $this->{__.$column});'."\n".
															 t(4).'return true;'."\n".
														 t(3).'}'."\n";
										$contentM .= t(3).'if ($value["error"] == 1 || $value["error"] == 2)'."\n".
													 t(3).'{'."\n".
														 t(4).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_SIZE";'."\n".
														 t(4).'return false;'."\n".
													 t(3).'}'."\n".
													 t(3).'else'."\n".
													 t(3).'{'."\n".
														 t(4).'try {'."\n".
															 t(5).'if (!file_exists($this->_generic->getPathConfig("files").$this->_table))'."\n".
														 	 	t(6).'mkdir($this->_generic->getPathConfig("files").$this->_table,0755);'."\n\n".
															 t(5).'$token = substr(md5(time().substr(sha1(microtime()),0,rand(5,12))),mt_rand(1,20),10);'."\n".
															 t(5).'$fileName = SLS_String::sanitize(SLS_String::substrBeforeLastDelimiter($value["name"],"."),"_")."_".$token.".".SLS_String::substrAfterLastDelimiter($value["name"],".");'."\n".
															 t(5).'rename($value["tmp_name"],$this->_generic->getPathConfig("files").$this->_table."/".$fileName);'."\n".
															 t(5).'$value = $this->_table."/".$fileName;'."\n".
														 t(4).'}'."\n".
														 t(4).'catch (Exception $e) {'."\n".
															 t(5).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n".
															 t(5).'return false;'."\n".
														 t(4).'}'."\n".
													 t(3).'}'."\n".
													 t(2).'}'."\n\n";
										break;
									case "file_img":
										$contentM .= t(2).'if (!empty($this->__'.$column.'))'."\n".
													 t(2).'{'."\n".
														 t(3).'$this->deleteFiles(array("'.$column.'"));'."\n".
														 t(3).'$this->__'.$column.' = "__Uploads/__Deprecated/".$this->__'.$column.';'."\n".
														 t(3).'$this->save();'."\n".
													 t(2).'}'."\n\n".
													 t(2).'if (is_array($value))'."\n".
													 t(2).'{'."\n";
										if ($columns[$i]->Null == "YES")
											$contentM .= t(3).'if ($value["error"] == 4)'."\n".
														 t(3).'{'."\n".
															 t(4).'$this->__set(\''.$column.'\',(empty($this->{__.$column})) ? "" : $this->{__.$column});'."\n".
															 t(4).'return true;'."\n".
														 t(3).'}'."\n";
										$contentM .= t(3).'if ($value["error"] == 1 || $value["error"] == 2)'."\n".
													 t(3).'{'."\n".
														 t(4).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_SIZE";'."\n".
														 t(4).'return false;'."\n".
													 t(3).'}'."\n".
													 t(3).'else'."\n".
													 t(3).'{'."\n".
														 t(4).'try {'."\n".
															 t(5).'if (!file_exists($this->_generic->getPathConfig("files").$this->_table))'."\n".
												 			 	t(6).'mkdir($this->_generic->getPathConfig("files").$this->_table,0755);'."\n\n".
															 t(5).'$tmpName = SLS_String::substrBeforeLastDelimiter($value["tmp_name"],"/")."/".$value["name"];'."\n".
															 t(5).'$token = substr(md5(time().substr(sha1(microtime()),0,rand(5,12))),mt_rand(1,20),10);'."\n".
															 t(5).'$fileName = SLS_String::sanitize(SLS_String::substrBeforeLastDelimiter($value["name"],"."),"_")."_".$token;'."\n".
															 t(5).'@rename($value["tmp_name"],$tmpName);'."\n".
														 	 t(5).'$extension = pathinfo($tmpName, PATHINFO_EXTENSION);'."\n\n".
															 t(5).'// Check img'."\n".
															 t(5).'$img = new SLS_Image($tmpName);'."\n".
															 t(5).'if ($img->getParam("existed"))'."\n".
															 t(5).'{'."\n".
																 t(6).'$img->transform("","",$this->_generic->getPathConfig("files").$this->_table."/".$fileName.".".$extension,$extension);'."\n\n".													 
																 t(6).'// Check thumbs'."\n".
																 t(6).'$xmlType = new SLS_XMLToolbox(file_get_contents($this->_generic->getPathConfig("configSls")."/types.xml"));'."\n".
																 t(6).'$result = array_shift($xmlType->getTagsAttribute("//sls_configs/entry[@table=\'".$this->getDatabase()."_".$this->getTable()."\' and @column=\'".'.$column.'."\' and @type=\'file_img\']","thumbs"));'."\n".
																 t(6).'$thumbs = unserialize(str_replace("||#||",\'"\',$result["attribute"]));'."\n".
																 t(6).'if (!empty($thumbs))'."\n".
																 t(6).'{'."\n".
																	 t(7).'for($i=0 ; $i<$count=count($thumbs) ; $i++)'."\n".
																	 t(7).'{'."\n".
															 			t(8).'$img->transform($thumbs[$i]["width"],$thumbs[$i]["height"],$this->_generic->getPathConfig("files").$this->_table."/".$fileName.$thumbs[$i]["suffix"].".".$extension,$extension);'."\n".
																	 t(7).'}'."\n".
															 	 t(6).'}'."\n".
															 t(5).'}'."\n".
															 t(5).'else'."\n".
															 t(5).'{'."\n".
																 t(6).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n".
																 t(6).'return false;'."\n".
															 t(5).'}'."\n".
															 t(5).'$value = $this->_table."/".$fileName.".".$extension;'."\n".
														 t(4).'}'."\n".
														 t(4).'catch (Exception $e) {'."\n".
															 t(5).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n".
															 t(5).'return false;'."\n".
														 t(4).'}'."\n".
													 t(3).'}'."\n".
												t(2).'}'."\n\n";
										break;
								}
								break;
							}
						}
					}
					 			 
					// Not Nullable
					if ($columns[$i]->Null == "NO")
					{
						$contentM .= t(2).'if ($value === "")'."\n".
									 t(2).'{'."\n".
										 t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_EMPTY";'."\n".
										 t(3).'return false;'."\n".
									 t(2).'}'."\n\n";						
					
						if ($isPassword)
						{
							$result = array_shift($xmlFilter->getTagsAttribute("//sls_configs/entry[@table='".$db."_".$tableName."' and @column='".$column."']","hash"));
							$hash = (empty($result["attribute"])) ? "sha1" : $result["attribute"];
							$contentM .= t(2).'if ($value != $this->__'.$column.')'."\n".
										 	t(3).'$value = SLS_String::filter($value,"hash","'.$hash.'");'."\n\n";
						}
						
						$contentM .= t(2).'if (is_null($value))'."\n".
									 t(2).'{'."\n".
										 t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_NULL";'."\n".
										 t(3).'return false;'."\n".
									 t(2).'}'."\n\n";
					}
					
					// Check change
					$contentM .= t(2).'if ($this->__'.$column.' == $value)'."\n".								 
					 			 	t(3).'return true;'."\n\n";
					
					// Unique
					if ($columns[$i]->Key == "UNI")
					{
						$contentM .= t(2).'if (!$this->isUnique(\''.SLS_String::addSlashes($column, 'QUOTES').'\',$value))'."\n".
									 t(2).'{'."\n".
										 t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_UNIQUE";'."\n".
										 t(3).'return false;'."\n".
									 t(2).'}'."\n\n";
					}
					
					// Float types
					if (SLS_String::startsWith($columnType,"float") || SLS_String::startsWith($columnType,"double") || SLS_String::startsWith($columnType,"decimal"))
					{
						$length = SLS_String::substrBeforeFirstDelimiter(SLS_String::substrAfterFirstDelimiter(SLS_String::substrBeforeLastDelimiter($columns[$i]->Type, ')'), '('), ",");
						if (empty($length))
							$length = "25";
						$contentM .= t(2).'$decimal = (strpos($value, \',\')) ? str_replace(\',\', \'.\', $value) : (!strpos($value, \'.\')) ? $value.\'.0\' : $value;'."\n".									
									 t(2).'if (!is_numeric($decimal))'."\n".
									 t(2).'{'."\n".
										 t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n".
										 t(3).'return false;'."\n".
									 t(2).'}'."\n\n".
									 t(2).'if ((strlen($decimal)-1) > '.$length.')'."\n".
									 t(2).'{'."\n".
										 t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_LENGTH";'."\n".
										 t(3).'return false;'."\n".
									 t(2).'}'."\n\n";
					}
					
					// Enum types
					else if ($columnType == "enum" || $columnType == "set")
					{						
						$values = SLS_String::substrAfterFirstDelimiter(SLS_String::substrBeforeLastDelimiter($columns[$i]->Type, "')"), "('");
						
						if ($columnType == "enum")
						{
							$contentM .= t(2).'$values = explode("\',\'", "'.str_replace("''", "\'", $values).'");'."\n".									
										 t(2).'if (!in_array($value, $values))'."\n".
										 t(2).'{'."\n".
											 t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_CONTENT";'."\n".
											 t(3).'return false;'."\n".
										 t(2).'}'."\n\n";
						}
						else
						{
							$contentM .= t(2).'$values = explode("\',\'", "'.str_replace("''", "\'", $values).'");'."\n".
										 t(2).'$valueE = explode(",",$value);'."\n".
								         t(2).'foreach($valueE as $set)'."\n".
								         t(2).'{'."\n".
											 t(3).'if (!in_array($set, $values))'."\n".
											 t(3).'{'."\n".
												 t(4).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_CONTENT";'."\n".
												 t(4).'return false;'."\n".
											 t(3).'}'."\n".
										 t(2).'}'."\n\n";
						}									 
					}
					else 
					{						
						if (strpos($columns[$i]->Type, "("))
						{
							$length = SLS_String::substrAfterFirstDelimiter(SLS_String::substrBeforeLastDelimiter($columns[$i]->Type, ")"), "(");
							$contentM .= t(2).'if (strlen($value) > '.$length.')'."\n".
										 t(2).'{'."\n".
											 t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_LENGTH";'."\n".
											 t(3).'return false;'."\n".
										 t(2).'}'."\n\n";
						}
						if(SLS_String::endsWith($columnType, "int"))
						{
							$contentM .= t(2).'if (!is_numeric($value))'."\n".
										 t(2).'{'."\n".
											 t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n".
											 t(3).'return false;'."\n".
										 t(2).'}'."\n\n";
						}
						else if ($columnType == "date" || $columnType == "datetime" || $columnType == "timestamp")
						{
							switch ($columnType)
							{
								case "date":
									$contentM .= t(2).'if (!SLS_Date::isDate($value))'."\n";
									break;
								case "datetime":
									$contentM .= t(2).'if (!SLS_Date::isDateTime($value))'."\n";
									break;
								case "timestamp":
									$contentM .= t(2).'if (!SLS_Date::isDateTime($value))'."\n";
									break;
							}
							$contentM .= t(2).'{'."\n".
											 t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n".
											 t(3).'return false;'."\n".
										 t(2).'}'."\n\n";
						}
						else if ($columnType == "time" || $columnType == "year")
						{
							switch ($columnType)
							{
								case "time":
									$contentM .= t(2).'if (strpos(\':\', $value) && substr_count($value, \':\') != 2)'."\n".
	 											 t(2).'{'."\n".
		 											 t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n".
													 t(3).'return false;'."\n".
												 t(2).'}'."\n\n".
												 t(2).'$check = explode(\':\', $value);'."\n".	
												 t(2).'if (count($check) == 1 && !is_numeric($check[0]))'."\n".	
												 t(2).'{'."\n".
		 											 t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n".
													 t(3).'return false;'."\n".
												 t(2).'}'."\n".
												 t(2).'else if ((count($check) > 1) && (!is_numeric($check[0]) || (!is_numeric($check[1]) || strlen($check[1]) > 2) || (!is_numeric($check[2]) || strlen($check[2]) > 2)))'."\n".	
												 t(2).'{'."\n".
		 											 t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n".
													 t(3).'return false;'."\n".
												 t(2).'}'."\n\n";
									break;
								case "year":
									$contentM .= t(2).'if (!mktime(0, 0, 0, 0, 0, $value))'."\n".
	 											 t(2).'{'."\n".
		 											 t(3).'$this->_typeErrors[\''.SLS_String::addSlashes($column, 'QUOTES').'\'] = "E_TYPE";'."\n".
													 t(3).'return false;'."\n".
												 t(2).'}'."\n\n";
									break;
							}
						}
						
					}
					$contentM .= 		t(2).'$this->__set(\''.$column.'\', $value);'."\n".
										t(2).'return true;'."\n".
									t(1).'}'."\n\n";
				}
			}						
		}
		
		// Get FKs to create access reference functions
		$fks = $xmlFk->getTagsAttributes("//sls_configs/entry[@tableFk='".$db."_".$tableName."']",array("columnFk","tablePk"));
		for($i=0 ; $i<$count=count($fks) ; $i++)
		{
			$columnFk = $fks[$i]["attributes"][0]["value"];
			$tablePk = $fks[$i]["attributes"][1]["value"];
			
			$functionName = SLS_String::fullTrim(ucwords(SLS_String::stringToUrl(SLS_String::tableToClass(SLS_String::substrAfterFirstDelimiter($tablePk,"_"))," ",false)),"");
			$functionName{0} = strtolower($functionName{0});
			$contentM .= t(1).'/**'."\n".
					     t(1).' * Get the instance of '.SLS_String::substrAfterFirstDelimiter($tablePk,"_").'\'s Model'."\n".  
					     t(1).' * @author SillySmart'."\n".
					     t(1).' * @copyright SillySmart'."\n".
					     t(1).' * @return '.SLS_String::tableToClass($tablePk).' $object the instance of '.SLS_String::substrAfterFirstDelimiter($tablePk,"_").'\'s Model'."\n".
					     t(1).' */'."\n".
						 t(1).'public function '.$functionName.'()'."\n".
						 t(1).'{'."\n".
							 t(2).'$this->_generic->useModel("'.SLS_String::tableToClass(SLS_String::substrAfterFirstDelimiter($tablePk,"_")).'","'.SLS_String::substrBeforeFirstDelimiter($tablePk,"_").'");'."\n".
						     t(2).'$object = new '.ucfirst(SLS_String::substrBeforeFirstDelimiter($tablePk,"_")).'_'.SLS_String::tableToClass(SLS_String::substrAfterFirstDelimiter($tablePk,"_")).'();'."\n".
						     t(2).'$object->getModel($this->__'.$columnFk.');'."\n".
						     t(2).'return $object;'."\n".
						 t(1).'}';
			$contentM .= ($i == ($count-1)) ? "\n" : "\n\n";
		}
		
		$contentM .= '}'."\n".
					 '?>';
		
		return $contentM;
	}
}
?>